From 3926ea55973c844f7808d64b34c56782b057a041 Mon Sep 17 00:00:00 2001 From: shridhar Date: Fri, 3 May 2024 14:49:10 +0530 Subject: [PATCH] fix: upload document based on header type --- .../doctype/whatsapp_templates/whatsapp_templates.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.py b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.py index 02c9be3..b85437e 100644 --- a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.py +++ b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_templates/whatsapp_templates.py @@ -19,8 +19,9 @@ def validate(self): lang_code = frappe.db.get_value("Language", self.language) or "en" self.language_code = lang_code.replace("-", "_") - self.get_session_id() - self.get_media_id() + if self.header_type in ["IMAGE", "DOCUMENT"] and self.sample: + self.get_session_id() + self.get_media_id() if not self.is_new(): self.update_template() @@ -31,11 +32,11 @@ def get_session_id(self): self.get_settings() file_path = self.get_absolute_path(self.sample) mime = magic.Magic(mime=True) - mime.from_file(file_path) + file_type = mime.from_file(file_path) payload = { 'file_length': os.path.getsize(file_path), - 'file_type': 'image/png', + 'file_type': file_type, 'messaging_product': 'whatsapp' }