Skip to content

Commit

Permalink
Merge pull request #64 from shariquerik/send-receive-reply
Browse files Browse the repository at this point in the history
feat: Send & Receive reply
  • Loading branch information
shridarpatil authored Apr 21, 2024
2 parents a125ce5 + 8db4c1f commit 7ce36c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
"from",
"use_template",
"template",
"reply_to_message_id",
"column_break_5",
"message",
"message_type",
"message_id",
"conversation_id",
"content_type",
"attach",
"section_break_iyjf",
"is_reply",
"reply_to_message_id",
"section_break_dhba",
"reference_doctype",
"column_break_efrb",
Expand Down Expand Up @@ -147,11 +149,21 @@
"fieldname": "reply_to_message_id",
"fieldtype": "Data",
"label": "Reply To Message ID"
},
{
"fieldname": "section_break_iyjf",
"fieldtype": "Section Break"
},
{
"default": "0",
"fieldname": "is_reply",
"fieldtype": "Check",
"label": "Is Reply"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-04-20 22:29:37.844813",
"modified": "2024-04-21 12:11:56.505002",
"modified_by": "Administrator",
"module": "Frappe Whatsapp",
"name": "WhatsApp Message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def before_insert(self):
"to": self.format_number(self.to),
"type": self.content_type
}
if self.is_reply and self.reply_to_message_id:
data["context"] = {"message_id": self.reply_to_message_id}
if self.content_type in ['document', 'image', 'video']:
data[self.content_type.lower()] = {
"link": link,
Expand Down
6 changes: 6 additions & 0 deletions frappe_whatsapp/utils/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ def post():
if messages:
for message in messages:
message_type = message['type']
is_reply = True if message.get('context') else False
reply_to_message_id = message['context']['id'] if is_reply else None
if message_type == 'text':
frappe.get_doc({
"doctype": "WhatsApp Message",
"type": "Incoming",
"from": message['from'],
"message": message['text']['body'],
"message_id": message['id'],
"reply_to_message_id": reply_to_message_id,
"is_reply": is_reply,
"content_type":message_type
}).insert(ignore_permissions=True)
elif message_type == 'reaction':
Expand Down Expand Up @@ -105,6 +109,8 @@ def post():
"type": "Incoming",
"from": message['from'],
"message_id": message['id'],
"reply_to_message_id": reply_to_message_id,
"is_reply": is_reply,
"message": message[message_type].get("caption",f"/files/{file_name}"),
"content_type" : message_type
}).insert(ignore_permissions=True)
Expand Down

0 comments on commit 7ce36c4

Please sign in to comment.