summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/wati.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-11-29 10:05:58 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-11-29 10:05:58 +0700
commit8906f678c23090d70d16191dc1fe76e518e8e9d9 (patch)
treea98cb41a39064f692d764338177b84fd14bed82a /indoteknik_custom/models/wati.py
parentd0bd4a82c923789a931f9433085f4219c6d7346a (diff)
parent0080b6b1da5f181cee32fae7bb5166ce65165374 (diff)
Merge branch 'production' into CR/quotation-noPo
# Conflicts: # indoteknik_custom/models/user_company_request.py
Diffstat (limited to 'indoteknik_custom/models/wati.py')
-rw-r--r--indoteknik_custom/models/wati.py57
1 files changed, 36 insertions, 21 deletions
diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py
index eed5413e..f3632334 100644
--- a/indoteknik_custom/models/wati.py
+++ b/indoteknik_custom/models/wati.py
@@ -58,41 +58,56 @@ class WatiNotification(models.Model):
return
def _create_wati_history_header(self, ticket_id, sender_name, notification_json, date_wati):
+ # Helper function to remove NUL characters
+ def remove_null_characters(value):
+ if isinstance(value, str):
+ return value.replace('\0', '')
+ return value
+
+ # Sanitize the input data
param_header = {
'ticket_id': ticket_id,
- 'conversation_id': notification_json['conversationId'],
- 'sender_name': sender_name,
- 'wa_id': notification_json['waId'],
- 'text': notification_json['text'],
- 'date_wati': date_wati or '',
+ 'conversation_id': remove_null_characters(notification_json.get('conversationId', '')),
+ 'sender_name': remove_null_characters(sender_name),
+ 'wa_id': remove_null_characters(notification_json.get('waId', '')),
+ 'text': remove_null_characters(notification_json.get('text', '')),
+ 'date_wati': remove_null_characters(date_wati or ''),
}
+
+ # Create the record
new_header = self.env['wati.history'].create([param_header])
return new_header
def _create_wati_history_line(self, new_header, ticket_id, sender_name, notification_json, date_wati):
- text_body = notification_json['text'] or ''
+ # Helper function to remove NUL characters
+ def remove_null_characters(value):
+ if isinstance(value, str):
+ return value.replace('\0', '')
+ return value
+
+ # Sanitize the input data
param_line = {
"wati_history_id": new_header.id,
- "conversation_id": notification_json['conversationId'],
- "data": notification_json['data'] or '',
- "event_type": notification_json['eventType'] or '',
- # "list_reply": notification_json['listReply'] or '',
- # "message_contact": notification_json['messageContact'] or '',
- "operator_email": notification_json['operatorEmail'] or '',
- "operator_name": notification_json['operatorName'] or '',
- "sender_name": sender_name or '',
- # "source_url": notification_json['sourceUrl'] or '',
- "status_string": notification_json['statusString'] or '',
- "text": text_body,
+ "conversation_id": remove_null_characters(notification_json.get('conversationId', '')),
+ "data": remove_null_characters(notification_json.get('data', '')),
+ "event_type": remove_null_characters(notification_json.get('eventType', '')),
+ "operator_email": remove_null_characters(notification_json.get('operatorEmail', '')),
+ "operator_name": remove_null_characters(notification_json.get('operatorName', '')),
+ "sender_name": remove_null_characters(sender_name or ''),
+ "status_string": remove_null_characters(notification_json.get('statusString', '')),
+ "text": remove_null_characters(notification_json.get('text', '')),
"ticket_id": ticket_id,
- "type": notification_json['type'] or '',
- "wa_id": notification_json['waId'] or '',
- "date_wati": date_wati or '',
+ "type": remove_null_characters(notification_json.get('type', '')),
+ "wa_id": remove_null_characters(notification_json.get('waId', '')),
+ "date_wati": remove_null_characters(date_wati or ''),
}
+
+ # Create the record safely without NUL characters
self.env['wati.history.line'].create([param_line])
- self._update_header_after_create_line(new_header, sender_name, date_wati, text_body)
+ self._update_header_after_create_line(new_header, sender_name, date_wati, param_line['text'])
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