Skip to content

Not receiving Interactive message via webhook (BUG) #151

@elbeicktalat

Description

@elbeicktalat

@shridarpatil Thank you for your grate code,
I'm facing a critical issue with receiving a message.

My Request:

whatsapp_settings = frappe.get_doc('WhatsApp Settings')

url = f"{whatsapp_settings.url}/{whatsapp_settings.version}/{whatsapp_settings.phone_id}/messages"
headers = {
  "Authorization": "Bearer ",
  "Content-Type": "application/json"
}

data = {
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "+39**********",
  "type": "interactive",
  "interactive": {
    "type": "button",
    "header": {
      "type": "text",
      "text": f"{frappe.utils.today()}"
    },
    "body": {
      "text": "Ciao Bello"
    },
    "action": {
      "buttons": [
        {
          "type": "reply",
          "reply": {
            "id": "BUTTON_ID_1",
            "title": "1.000"
          }
        },
        {
          "type": "reply",
          "reply": {
            "id": "BUTTON_ID_2",
            "title": "2.000"
          }
        },
        {
          "type": "reply",
          "reply": {
            "id": "BUTTON_ID_3",
            "title": "3.000"
          }
        }
      ]
    }
  }
}

frappe.make_post_request(url, data=json.dumps(data), headers=headers)

The Frappe Error Log

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/app.py", line 115, in application
    response = frappe.api.handle(request)
      request = <Request 'https://examle.com/api/method/frappe_whatsapp.utils.webhook.webhook' [POST]>
      response = None
      rollback = True
      e = KeyError('nfm_reply')
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
      request = <Request 'https://examle.com/api/method/frappe_whatsapp.utils.webhook.webhook' [POST]>
      endpoint = <function handle_rpc_call at 0x7f652c980040>
      arguments = {'method': 'frappe_whatsapp.utils.webhook.webhook'}
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
      method = 'frappe_whatsapp.utils.webhook.webhook'
      frappe = <module 'frappe' from 'apps/frappe/frappe/__init__.py'>
  File "apps/frappe/frappe/handler.py", line 51, in handle
    data = execute_cmd(cmd)
      cmd = 'frappe_whatsapp.utils.webhook.webhook'
      data = None
  File "apps/frappe/frappe/handler.py", line 84, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
      cmd = 'frappe_whatsapp.utils.webhook.webhook'
      from_async = False
      server_script = None
      method = <function webhook at 0x7f65290df420>
  File "apps/frappe/frappe/__init__.py", line 1754, in call
    return fn(*args, **newargs)
      fn = <function webhook at 0x7f65290df420>
      args = ()
      kwargs = {'object': 'whatsapp_business_account', 'entry': [{'id': '<****>', 'changes': [{'value': {'messaging_product': 'whatsapp', 'metadata': {'display_phone_number': '<****>', 'phone_number_id': '<****>'}, 'contacts': [{'profile': {'name': 'Ita'}, 'wa_id': 'phone_no'}], 'messages': [{'context': {'from': '393518416260', 'id': 'wamid.HBgMMzkzMzE0ODIwNTU2FQIAERgSMTFBRkI2QzhCMTA1Q0E2NEM4AA=='}, 'from': '<******>', 'id': 'wamid.HBgMMzkzMzE0ODIwNTU2FQIAEhggM0YzRjE3MUQ4QTJBOEIyQTk3RTc1MkY0RjAwOUNCOTEA', 'timestamp': '1752455667', 'type': 'interactive', 'interactive': {'type': 'button_reply', 'button_reply': {'id': 'BUTTON_ID_2', 'title': '2.000'}}}]}, 'field': 'messages'}]}], 'cmd': 'frappe_whatsapp.utils.webhook.webhook'}
      newargs = {}
  File "apps/frappe/frappe/utils/typing_validations.py", line 32, in wrapper
    return func(*args, **kwargs)
      args = ()
      kwargs = {}
      apply_condition = <function whitelist.<locals>.innerfn.<locals>.<lambda> at 0x7f65290df380>
      func = <function webhook at 0x7f65290df2e0>
  File "apps/frappe_whatsapp/frappe_whatsapp/utils/webhook.py", line 15, in webhook
    return post()
  File "apps/frappe_whatsapp/frappe_whatsapp/utils/webhook.py", line 88, in post
    "from": message['from'],
      data = {'object': 'whatsapp_business_account', 'entry': [{'id': '<*******>', 'changes': [{'value': {'messaging_product': 'whatsapp', 'metadata': {'display_phone_number': '393518416260', 'phone_number_id': '213199691887604'}, 'contacts': [{'profile': {'name': 'Kml'}, 'wa_id': '<****>'}], 'messages': [{'context': {'from': '<******>', 'id': 'wamid.HBgMMzkzMzE0ODIwNTU2FQIAERgSMTFBRkI2QzhCMTA1Q0E2NEM4AA=='}, 'from': 'phone_no', 'id': '<>', 'timestamp': '1752455667', 'type': 'interactive', 'interactive': {'type': 'button_reply', 'button_reply': {'id': 'BUTTON_ID_2', 'title': '2.000'}}}]}, 'field': 'messages'}]}], 'cmd': 'frappe_whatsapp.utils.webhook.webhook'}
      messages = [{'context': {'from': '<>', 'id': '<>'}, 'from': '<>', 'id': 'wamid.HBgMMzkzMzE0ODIwNTU2FQIAEhggM0YzRjE3MUQ4QTJBOEIyQTk3RTc1MkY0RjAwOUNCOTEA', 'timestamp': '1752455667', 'type': 'interactive', 'interactive': {'type': 'button_reply', 'button_reply': {'id': 'BUTTON_ID_2', 'title': '2.000'}}}]
      sender_profile_name = 'Kml'
      message = {'context': {'from': '393518416260', 'id': '<>'}, 'from': 'phone_no', 'id': '<>', 'timestamp': '1752455667', 'type': 'interactive', 'interactive': {'type': 'button_reply', 'button_reply': {'id': 'BUTTON_ID_2', 'title': '2.000'}}}
      message_type = 'interactive'
      is_reply = True
      reply_to_message_id = 'wamid.HBgMMzkzMzE0ODIwNTU2FQIAERgSMTFBRkI2QzhCMTA1Q0E2NEM4AA=='
builtins.KeyError: 'nfm_reply'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions