summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-11-30 10:31:56 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-11-30 10:31:56 +0700
commit6f93656ef914f40b13abfb320b539d4e54acac20 (patch)
tree4ffaceefbce86ebc11bf6fe3bcdd1d6d417a6fac
parentfae45d0b400ad9cf9bce61f11df4fccc3502c997 (diff)
parent607ad8509198265e467f3b43505e9f6f157bce35 (diff)
Merge branch 'production' of https://bitbucket.org/altafixco/indoteknik-addons into production
-rw-r--r--indoteknik_custom/models/wati.py59
1 files changed, 48 insertions, 11 deletions
diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py
index af1aa7b8..aa63fe92 100644
--- a/indoteknik_custom/models/wati.py
+++ b/indoteknik_custom/models/wati.py
@@ -2,6 +2,7 @@ from odoo import fields, models, api
from datetime import datetime, timedelta
import logging
import json
+import requests
_logger = logging.getLogger(__name__)
@@ -54,15 +55,7 @@ class WatiNotification(models.Model):
new_header = self._create_wati_history_header(ticket_id, sender_name, notification_json, date_wati)
self._create_wati_history_line(new_header, ticket_id, sender_name, notification_json, date_wati)
notification.is_parsed = True
-
- # notification.ticket_id = notification_json['ticketId']
- # notification.mobile = notification_json['waId']
- # notification.sender_name = sender_name
- # notification.text = notification_json['text']
- # notification.text_time = datetime.fromtimestamp(float(notification_json['timestamp']))
- # notification.text_type = notification_json['type']
- # notification.is_parsed = True
- # return
+ return
def _create_wati_history_header(self, ticket_id, sender_name, notification_json, date_wati):
param_header = {
@@ -97,15 +90,58 @@ class WatiNotification(models.Model):
"date_wati": date_wati or '',
}
self.env['wati.history.line'].create([param_line])
+ self._update_header_after_create_line(new_header, sender_name, date_wati, text_body)
+ return
+
+ def _update_header_after_create_line(self, new_header, sender_name, date_wati, text_body):
new_header.last_reply_by = sender_name
new_header.last_reply_date = date_wati
new_header.last_reply_text = text_body
if sender_name == 'Indoteknik':
current_time = date_wati
- # current_time_str = current_time.strftime('%Y-%m-%d %H:%M:%S')
delta_time = current_time + timedelta(days=1)
- # delta_time_str = delta_time.strftime('%Y-%m-%d %H:%M:%S')
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)
+
return
def _convert_to_leads(self):
@@ -175,6 +211,7 @@ class WatiNotification(models.Model):
class WatiHistory(models.Model):
_name = 'wati.history'
+ _order = 'id desc'
ticket_id = fields.Char(string='Ticket ID')
conversation_id = fields.Char(string='Conversation ID')