Bindambc / whatsapp-business-java-api

Whatsapp business api SDK, written in java. This SDK implements the Official Whatsapp Cloud API and WhatsApp Business Management API. These allows you to: manage your WhatsApp Business Account assets, such as message templates and phone numbers; send messages to your contacts, such as simple text messages, messages with buttons...
https://bindambc.github.io/whatsapp-business-java-api/
MIT License
137 stars 69 forks source link

Using the library for Whatstapp API version 19 #178

Open OldKalash7 opened 2 months ago

OldKalash7 commented 2 months ago

Hello. I'm currently building an application that needs to communicate with whatsapp api. In the meta panel, the version of the api it's 19 image

I'm trying to deserialize the test payload of a message webhook provided by meta, using the WebHook class.

{
  "field": "messages",
  "value": {
    "messaging_product": "whatsapp",
    "metadata": {
      "display_phone_number": "16505551111",
      "phone_number_id": "123456123"
    },
    "contacts": [
      {
        "profile": {
          "name": "test user name"
        },
        "wa_id": "16315551181"
      }
    ],
    "messages": [
      {
        "from": "16315551181",
        "id": "ABGGFlA5Fpa",
        "timestamp": "1504902988",
        "type": "text",
        "text": {
          "body": "this is a text message"
        }
      }
    ]
  }
}

I get the following error: Unrecognized field "field" (class com.whatsapp.api.domain.webhook.WebHookEvent), not marked as ignorable (2 known properties: "entry", "object"])

I saw the payload you provided in the example: https://github.com/Bindambc/whatsapp-business-java-api/blob/main/src/test/java/com/whatsapp/api/examples/WebHookExample.java

And it's different. This is expected due to the diffent versions (I'ts stated that the library supports 16)? Can the Webhook class be extended somehow to support this new type of payload?

Thanks in advance Mauricio.

github-actions[bot] commented 2 months ago

Hello and welcome! We're glad to see that you've opened your first issue. We appreciate your contribution and would love to hear more about the problem you're experiencing. Our team is actively monitoring this repository and we will do our best to respond to your issue as soon as possible. Thank you for using our project and we look forward to working with you!

Bindambc commented 1 month ago

Hello @OldKalash7,

I believe the JSON you posted is incomplete. In the payload, there are the fields 'object' and 'entry.' See the example below, which I also obtained from the v19 API

{
   "object": "whatsapp_business_account",
   "entry": [
      {
         "id": "0",
         "changes": [
            {
               "field": "messages",
               "value": {
                  "messaging_product": "whatsapp",
                  "metadata": {
                     "display_phone_number": "16505551111",
                     "phone_number_id": "123456123"
                  },
                  "contacts": [
                     {
                        "profile": {
                           "name": "test user name"
                        },
                        "wa_id": "16315551181"
                     }
                  ],
                  "messages": [
                     {
                        "from": "16315551181",
                        "id": "ABGGFlA5Fpa",
                        "timestamp": "1504902988",
                        "type": "text",
                        "text": {
                           "body": "this is a text message"
                        }
                     }
                  ]
               }
            }
         ]
      }
   ]
}