diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-11-30 14:33:36 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-11-30 14:33:36 +0700 |
| commit | 90507e2460b013309483906cff41e02576d5c31b (patch) | |
| tree | ffbf9bc17073fbc21b079db5ac60589a09c97db6 | |
| parent | 607ad8509198265e467f3b43505e9f6f157bce35 (diff) | |
get attribute from wati
| -rw-r--r-- | indoteknik_custom/models/wati.py | 108 |
1 files changed, 67 insertions, 41 deletions
diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index aa63fe92..00b46360 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -101,47 +101,10 @@ class WatiNotification(models.Model): current_time = date_wati delta_time = current_time + timedelta(days=1) new_header.expired_date = delta_time - if not new_header.perusahaan or not new_header.email: - self._get_attribute_wati(new_header) - return - - def _get_attribute_wati(self, new_header): - # url = 'https://live-server-2106.wati.io/api/v1/getContacts' - - # cookies = { - # 'affinity': '1701232090.884.1520.321410|ff187ffce9bc0bae13542bb446e41008', - # } - - # headers = { - # 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3MGM5ZmJhNy00MWRlLTRkMWEtYjY2NS1hM2Q5ODc2ZjhlZWIiLCJ1bmlxdWVfbmFtZSI6InR5YXNAaW5kb3Rla25pay5jb20iLCJuYW1laWQiOiJ0eWFzQGluZG90ZWtuaWsuY29tIiwiZW1haWwiOiJ0eWFzQGluZG90ZWtuaWsuY29tIiwiYXV0aF90aW1lIjoiMTEvMjkvMjAyMyAwNDoxNzo0NyIsImRiX25hbWUiOiIyMTA2IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQURNSU5JU1RSQVRPUiIsImV4cCI6MjUzNDAyMzAwODAwLCJpc3MiOiJDbGFyZV9BSSIsImF1ZCI6IkNsYXJlX0FJIn0.--KHv4GCOG2MM3lNW9Nm-0-d8OAVpn5kbcSX4JKqATQ', - # # 'Cookie': 'affinity=1701232090.884.1520.321410|ff187ffce9bc0bae13542bb446e41008', - # } - - # files = { - # 'pageSize': (None, '1'), - # 'pageNumber': (None, '1'), - # 'name': (None, ''), - # 'attribute': (None, '[{name: "phone", operator: "contain", value: "6285751430014"}]'), - # 'createdDate': (None, ''), - # } - - # response = requests.get(url, cookies=cookies, headers=headers, files=files) - # print(response.json()) - wati_api = self.env['wati.api'] - params = { - 'pageSize':1, - 'pageNumber':1, - 'attribute':[{'name': "phone", 'operator': "contain", 'value': "6285751430014"}], - } - wati_contacts = wati_api.http_get('/api/v1/getContacts', params) - if wati_contacts['result'] != 'success': - return - # print (wati_contacts) - json_dump = json.dumps(wati_contacts, indent=4, sort_keys=True) - contact_list = json.loads(json_dump)['contact_list'] - id = json.loads(contact_list)['id'] - print(id) - + # this commented code not run smoothly, need more time + # change to scheduler + # if not new_header.perusahaan or not new_header.email: + # self._get_attribute_wati(new_header) return def _convert_to_leads(self): @@ -226,6 +189,69 @@ class WatiHistory(models.Model): expired_date = fields.Datetime(string='Expired Date') email = fields.Char(string='Email') perusahaan = fields.Char(string='Perusahaan') + is_get_attribute = fields.Boolean(string='Get Attribute', default=False) + + def _get_attribute_wati(self, test): + # url = 'https://live-server-2106.wati.io/api/v1/getContacts' + + # cookies = { + # 'affinity': '1701232090.884.1520.321410|ff187ffce9bc0bae13542bb446e41008', + # } + + # headers = { + # 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3MGM5ZmJhNy00MWRlLTRkMWEtYjY2NS1hM2Q5ODc2ZjhlZWIiLCJ1bmlxdWVfbmFtZSI6InR5YXNAaW5kb3Rla25pay5jb20iLCJuYW1laWQiOiJ0eWFzQGluZG90ZWtuaWsuY29tIiwiZW1haWwiOiJ0eWFzQGluZG90ZWtuaWsuY29tIiwiYXV0aF90aW1lIjoiMTEvMjkvMjAyMyAwNDoxNzo0NyIsImRiX25hbWUiOiIyMTA2IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQURNSU5JU1RSQVRPUiIsImV4cCI6MjUzNDAyMzAwODAwLCJpc3MiOiJDbGFyZV9BSSIsImF1ZCI6IkNsYXJlX0FJIn0.--KHv4GCOG2MM3lNW9Nm-0-d8OAVpn5kbcSX4JKqATQ', + # # 'Cookie': 'affinity=1701232090.884.1520.321410|ff187ffce9bc0bae13542bb446e41008', + # } + + # files = { + # 'pageSize': (None, '1'), + # 'pageNumber': (None, '1'), + # 'name': (None, ''), + # 'attribute': (None, '[{name: "phone", operator: "contain", value: "6285751430014"}]'), + # 'createdDate': (None, ''), + # } + + # response = requests.get(url, cookies=cookies, headers=headers, files=files) + # print(response.json()) + domain = [ + '&', + ('is_get_attribute', '=', False), + '|', + ('perusahaan', '=', False), + ('email', '=', False), + ]#TODO must flagged after get attribute + limit = 50 + wati_histories = self.env['wati.history'].search(domain, limit=limit) + count = 0 + for wati_history in wati_histories: + count += 1 + _logger.info('[Parse Notification] Process: %s/%s' % (str(count), str(limit))) + wati_api = self.env['wati.api'] + params = { + 'pageSize':1, + 'pageNumber':1, + 'attribute':[{'name': "phone", 'operator': "contain", 'value': wati_history.wa_id}], + } + wati_contacts = wati_api.http_get('/api/v1/getContacts', params) + if wati_contacts['result'] != 'success': + return + json_dump = json.dumps(wati_contacts, indent=4, sort_keys=True) + contact_list = json.loads(json_dump)['contact_list'] + perusahaan = email = '' + for data in contact_list: + custom_params = data['customParams'] + for custom_param in custom_params: + name = custom_param['name'] + value = custom_param['value'] + if name == 'perusahaan': + perusahaan = value + elif name == 'email': + email = value + # end for 2 + # end for 1 + wati_history.perusahaan = perusahaan + wati_history.email = email + wati_history.get_attribute = True # @api.onchange('last_reply_date') # def _compute_expired_date(self): |
