Skip to content

Commit

Permalink
fix: set content type based on template header
Browse files Browse the repository at this point in the history
  • Loading branch information
shridarpatil committed Nov 23, 2023
1 parent 456f159 commit b3d8e81
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-19 18:27:53.611028",
"modified": "2023-11-23 14:59:58.002386",
"modified_by": "Administrator",
"module": "Frappe Whatsapp",
"name": "WhatsApp Message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ frappe.ui.form.on('WhatsApp Notification', {
frm.doc.template,
["template", "header_type"],
(r) => {
console.log(r)
if (r && r.template) {
frm.set_value('header_type', r.header_type)
frm.refresh_field("header_type")
Expand All @@ -32,7 +31,6 @@ frappe.ui.form.on('WhatsApp Notification', {
}

frm.refresh_field("custom_attachment")
console.log(frm.doc.custom_attachment)

frm.set_value("code", r.template);
frm.refresh_field("code")
Expand All @@ -41,7 +39,6 @@ frappe.ui.form.on('WhatsApp Notification', {
)
},
custom_attachment: function(frm){
console.log(frm.doc.custom_attachment)
if(frm.doc.custom_attachment && frm.doc.header_type == 'DOCUMENT'){
frm.set_df_property('attach', 'reqd', frm.doc.custom_attachment)
frm.set_df_property('file_name', 'reqd', frm.doc.custom_attachment)
Expand All @@ -56,7 +53,6 @@ frappe.ui.form.on('WhatsApp Notification', {
}
},
attach_document_print: function(frm){
console.log(frm.doc.header_type)
// frm.toggle_display("custom_attachment", !frm.doc.attach_document_print);
if(frm.doc.header_type == 'DOCUMENT'){
frm.set_value("custom_attachment", !frm.doc.attach_document_print)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def send_scheduled_message(self) -> dict:
"components": []
}
}

self.content_type = template.get("header_type", "text").lower()
self.notify(data)
# return _globals.frappe.flags

def send_template_message(self, doc: Document):
"""Specific to Document Event triggered Server Scripts."""
if self.disabled:
return

self.content_type = 'text'
doc_data = doc.as_dict()
if self.condition:
# check if condition satisfies
Expand Down Expand Up @@ -142,6 +142,7 @@ def send_template_message(self, doc: Document):
}
}]
})
self.content_type = template.header_type.lower()

self.notify(data)

Expand All @@ -168,7 +169,8 @@ def notify(self, data):
"message": str(data['template']),
"to": data['to'],
"message_type": "Template",
"message_id": response['messages'][0]['id']
"message_id": response['messages'][0]['id'],
"content_type": self.content_type
}).save(ignore_permissions=True)

frappe.msgprint("WhatsApp Message Triggered", indicator="green", alert=True)
Expand Down

0 comments on commit b3d8e81

Please sign in to comment.