shridarpatil / frappe_whatsapp

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

Error when sending a message with type Document #41

Closed ahassoun closed 1 year ago

ahassoun commented 1 year ago

Tried with .pdf and .docx files.

Text and images worked fine.

App Versions

{
    "chat": "0.0.1",
    "erpnext": "14.44.0",
    "frappe": "14.52.0",
    "frappe_whatsapp": "0.0.2",
    "hrms": "14.13.1",
    "insights": "1.1.3",
    "payments": "0.0.1",
}

Route

Form/WhatsApp Message/new-whatsapp-message-5

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 95, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 47, 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 1622, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/client.py", line 229, in save
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 307, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 329, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 255, in insert
    self.run_method("before_insert")
  File "apps/frappe/frappe/model/document.py", line 917, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1279, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1261, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 914, in fn
    return method_object(*args, **kwargs)
  File "apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_message/whatsapp_message.py", line 22, in before_insert
    "to": self.format_number(self.to),
  File "apps/frappe_whatsapp/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_message/whatsapp_message.py", line 82, in format_number
    if number.startswith("+"):
AttributeError: 'NoneType' object has no attribute 'startswith'

Request Data

{
    "type": "POST",
    "args": {
        "doc": "{\"docstatus\":0,\"doctype\":\"WhatsApp Message\",\"name\":\"new-whatsapp-message-5\",\"__islocal\":1,\"__unsaved\":1,\"owner\":\"Administrator\",\"type\":\"Outgoing\",\"message_type\":\"Manual\",\"content_type\":\"document\",\"__run_link_triggers\":1,\"attach\":\"/private/files/sample.docx\"}"
    },
    "freeze": true,
    "headers": {},
    "error_handlers": {},
    "url": "/api/method/frappe.client.save"
}

Response Data

{
    "exception": "AttributeError: 'NoneType' object has no attribute 'startswith'"
}
shridarpatil commented 1 year ago

From request body I can see that you have not entered mobile number and also the file which your uploading is not a pdf.

ahassoun commented 1 year ago

Thanks for the quick response. I tried to reproduce, but the error did not occur, however, the message was not sent.

Is there a log that I can check? WhatsApp Notification Log does not seem to have the manual messages?

shridarpatil commented 1 year ago

Notification log will have data only if you have setup webhook. Have you setup webhook?

ahassoun commented 1 year ago

Thanks! Looks all sorted out!

I already had the webhook setup in the first place, however, the webhook was pointing to the production domain while I was testing in the staging domain.

And now I can see the incoming messages which I couldn't see earlier for the same reason.

Thanks for the help, and for the plugin, please keep up the good work.

shridarpatil commented 1 year ago

Incoming messages works if you have webhook. As you said your webhook was pointed to production that could be the reason you couldn’t see incoming messages.

If you liked the plugin give it a star ⭐️ 😜