whatsapp-business-java-api icon indicating copy to clipboard operation
whatsapp-business-java-api copied to clipboard

Using the library for Whatstapp API version 19

Open OldKalash7 opened this issue 1 year ago • 2 comments
trafficstars

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.

OldKalash7 avatar Apr 17 '24 11:04 OldKalash7

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!

github-actions[bot] avatar Apr 17 '24 11:04 github-actions[bot]

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"
                        }
                     }
                  ]
               }
            }
         ]
      }
   ]
}

Bindambc avatar May 07 '24 03:05 Bindambc