shridarpatil / frappe_whatsapp

WhatsApp cloud integration for frappe
https://www.youtube.com/watch?v=nq5Kcc5e1oc
Other
188 stars 169 forks source link

message sent, but errors in doctype document #74

Closed lansgt closed 5 months ago

lansgt commented 5 months ago

When attempting to save, message is correctly sent, but I get this error:

image

Error: Value missing for WhatsApp Message: Content Type

KeyError: 'error' Possible source of error: frappe_whatsapp (app)

App Versions

{
    "custom_doctypes": "0.0.1",
    "erpnext": "15.23.3",
    "exchangedata": "0.0.1",
    "frappe": "15.27.0",
    "frappe_whatsapp": "0.0.2",
    "healthcare": "14.0.3",
    "hrms": "15.21.0",
    "leave_app": "0.0.1",
    "payments": "0.0.1"
}

Route

Form/Leave Application/new-leave-application-urqmygeihu

Traceback

Traceback (most recent call last):
  File "apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.py", line 189, in notify
    frappe.get_doc({
  File "apps/frappe/frappe/model/document.py", line 337, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 359, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 292, in insert
    self._validate()
  File "apps/frappe/frappe/model/document.py", line 574, in _validate
    self._validate_mandatory()
  File "apps/frappe/frappe/model/document.py", line 911, in _validate_mandatory
    raise frappe.MandatoryError(
frappe.exceptions.MandatoryError: [WhatsApp Message, 8dclqi0ppk]: content_type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1768, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/frappe/frappe/desk/form/save.py", line 39, in savedocs
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 337, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 359, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 315, in insert
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1128, in run_post_save_methods
    self.run_method("on_update")
  File "apps/frappe/frappe/model/document.py", line 962, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1322, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1306, in runner
    add_to_return_value(self, f(self, method, *args, **kwargs))
  File "apps/frappe_whatsapp/frappe_whatsapp/utils/__init__.py", line 27, in run_server_script_for_doc_event
    ).send_template_message(doc)
  File "apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.py", line 170, in send_template_message
    self.notify(data)
  File "apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.py", line 202, in notify
    response = frappe.flags.integration_request.json()['error']
KeyError: 'error'

Request Data

{
    "type": "POST",
    "args": {
        "doc": "{\"docstatus\":0,\"doctype\":\"Leave Application\",\"name\":\"new-leave-application-urqmygeihu\",\"__islocal\":1,\"__unsaved\":1,\"owner\":\"samp@samp.com\",\"naming_series\":\"LIC-.\",\"fecha_crea\":\"2024-06-08\",\"tipo_lic\":\"\",\"company\":\"samp\",\"half_day\":0,\"custom_hours\":0,\"hora_inic_sol\":\"00:00\",\"hora_fin_sol\":\"00:00\",\"hora_inic\":\"00:00\",\"hora_fin\":\"00:00\",\"hora_cita\":\"00:00\",\"doc_sol\":\"\",\"const\":\"\",\"follow_via_email\":1,\"posting_date\":\"2024-06-08\",\"status\":\"Open\",\"letter_head\":\"Membrete Samp\",\"leave_type\":\"Vacaciones\",\"employee\":\"CUE-10022\",\"leave_approver\":\"samp@samp.com\",\"leave_approver_name\":\"You\",\"employee_name\":\"Samp samp samp samp\",\"custom_col_dpi\":null,\"custom_empjoining\":\"2014-08-15\",\"custom_emp_branch\":\"Oficina\",\"department\":\"Administracion - Lans\",\"custom_col_phone\":\"+50256942010\",\"fecha_alta_vac\":\"2014-08-15\",\"from_date\":\"2024-06-10\",\"half_day_date\":\"\",\"to_date\":\"2024-06-11\",\"total_leave_days\":2,\"leave_balance\":48.618,\"fecha_reg_lab\":\"2024-06-12\"}",
        "action": "Save"
    },
    "btn": {
        "jQuery370028253802060637281": {
            "events": {
                "click": [
                    {
                        "type": "click",
                        "origType": "click",
                        "guid": 878,
                        "namespace": ""
                    }
                ]
            }
        }
    },
    "freeze": true,
    "headers": {},
    "error_handlers": {},
    "url": "/api/method/frappe.desk.form.save.savedocs",
    "request_id": null
}

Response Data

{
    "exception": "KeyError: 'error'",
    "exc_type": "KeyError",
    "_exc_source": "frappe_whatsapp (app)",
    "_server_messages": "[\"{\\\"message\\\": \\\"Email sent to samp@samp.com\\\", \\\"title\\\": \\\"Message\\\"}\", \"{\\\"message\\\": \\\"Error: Value missing for WhatsApp Message: Content Type\\\", \\\"title\\\": \\\"Message\\\"}\"]"
}

I've noticed this error appears to remain in cache, even after modifying the document to no longer send email to samp@samp.com, the error retains that error message.

This was on a template with no variables.

On another template with variables, if I attempted to use dates, the message would not be sent. If variables are changed to text, then it gets sent, but still shows the error message.

Please help.

shridarpatil commented 5 months ago

This is fixed you can pull the master branch.