Handling different Webhooks payloads from WhatsApp Api | RestApi

0
Hello everyone,I would like to process the message webhook from WhatsApp-Api.What is not clear to me at the moment, how can I process different JSON (specific webhooks payload) information?I have stored the Mendix RestAPI as POST in Meta in Webhooks.I can process my defined JSCON structure, but how do I handle the different information?   This is the baseline of the format { "object": "whatsapp_business_account", "entry": [{ "id": "WHATSAPP_BUSINESS_ACCOUNT_ID", "changes": [{ "value": { "messaging_product": "whatsapp", "metadata": { "display_phone_number": "PHONE_NUMBER", "phone_number_id": "PHONE_NUMBER_ID" }, # specific Webhooks payload }, "field": "messages" }] }] } Source: Webhooks-Setup - Cloud API (facebook.com)     This is the specific payload from deliverd message Source: Payload-Beispiele - Cloud API (facebook.com) { "object": "whatsapp_business_account", "entry": [{ "id": "WHATSAPP_BUSINESS_ACCOUNT_ID", "changes": [{ "value": { "messaging_product": "whatsapp", "metadata": { "display_phone_number": "PHONE_NUMBER", "phone_number_id": "PHONE_NUMBER_ID" }, "statuses": [{ "id": "wamid.ID", "recipient_id": "PHONE_NUMBER", "status": "delivered", "timestamp": "TIMESTAMP", "conversation": { "id": "CONVERSATION_ID", "expiration_timestamp": TIMESTAMP, "origin": { "type": "user_initiated" } }, "pricing": { "pricing_model": "CBP", "billable": true, "category": "service" } }] }, "field": "messages" }] }] }   Message read { "object": "whatsapp_business_account", "entry": [ { "id": "WHATSAPP_BUSINESS_ACCOUNT_ID", "changes": [ { "value": { "messaging_product": "whatsapp", "metadata": { "display_phone_number": "BUSINESS_DISPLAY_PHONE_NUMBER", "phone_number_id": "BUSINESS_PHONE_NUMBER_ID" }, "statuses": [ { "id": "WHATSAPP_MESSAGE_ID", "status": "read", "timestamp": "TIMESTAMP", "recipient_id": "CUSTOMER_PHONE_NUMBER" } ] }, "field": "messages" } ] } ] } how can i process these different payloads? since i can only specify one endpoint as destination in mendix...   Thank you in advance   Mike
asked
1 answers
1

Hey Michael,

 

Thanks for asking the question. At the moment I haven't tried it out, but did some research from my end to answer your question. So basically the WhatsApp webhook will be sending data in no-SQL structure which is not friendly for Mendix. But still, we can overcome this,

 

I found this article where they explain about notification payload send by whatsapp - https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components

 

{
  "object": "whatsapp_business_account",
  "entry": [{
    "id": "WHATSAPP-BUSINESS-ACCOUNT-ID",
    "changes": [{
      "value": {
         "messaging_product": "whatsapp",
         "metadata": {
           "display_phone_number": "PHONE-NUMBER",
           "phone_number_id": "PHONE-NUMBER-ID"
         },
      # Additional arrays and objects
         "contacts": [{...}]
         "errors": [{...}]
         "messages": [{...}]
         "statuses": [{...}]
      },
      "field": "messages"
    }]
  }]
}

 

279222632_734660030860914_6012822392536302447_n.png

 

For quick reference, I am pasting the complete payload structure that WhatsApp uses, but in the future, if they change this then your code will break. But for now, in Mendix you need to define the complete JSON structure (or at least the one which you need for the alerts) and then generate import mapping out of it.

 

Hope this helps.

 

Thanks & Regards,

Naman Khard

answered