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

WebHookExample

Open eos1d3 opened this issue 2 years ago • 7 comments
trafficstars

Hi,

I am studying how to use this library. The only thing I am confused is how to use WebHook. From WebHookExample, it does not setup Token or URL. Does this library need another web server running to receive WebHook events? And how to link the server to this library?

I also do not find any user callback to get WebHook event, nor any WebHook subscription in this library.

Need further clarifications for this. Thanks!

eos1d3 avatar Apr 17 '23 09:04 eos1d3

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 '23 09:04 github-actions[bot]

Hello @eos1d3,

From WebHookExample, it does not setup Token or URL.

You should implement the webhook APIs. This library provides an interface for the event received on the webhook from WhatsApp.

You must implement 2 endpoint without authorization

  1. GET - To verify the webhook with WA
  2. POST - To receive the event when WA send it.

This is an example of verify endpoint:

@GET
@Path("/webhook")
public Response verify(@NotNull @QueryParam("hub.mode") String mode,
                     @NotNull @QueryParam("hub.challenge") String challenge,
                     @NotNull @QueryParam("hub.verify_token") String verifyToken);

This is an example of processEvent endpoint:

@POST
@Path("/webhook")
public Response processEvent(@NotNull String payload);

The examples are written with Quarkus and Java 11.

  1. The token must be verified from you in business logic.
  2. The URL must be in HTTPS and set it into https://developers.facebook.com/apps/{YOUR_APP_ID}/whatsapp-business/wa-settings/?business_id={YOUR_BUSINESS_ID}
  3. See this guide to set the webhook.. https://developers.facebook.com/docs/whatsapp/cloud-api/get-started#configure-webhooks
  4. To test fastly I recommend you using Glitch or Heroku.

Hope this may be helpful!

pcomp96 avatar Apr 17 '23 14:04 pcomp96

Thanks a lot. I will try later with a real test.

eos1d3 avatar Apr 17 '23 15:04 eos1d3

Hello,

Thanks @pcomp96 for your contribution.

@eos1d3, as @pcomp96 mentioned, you need to implement the endpoints for the webhook.

You can use this library to deserialize an event received on the webhook:

public void processEvent(@NotNull String payload);
       WebHookEvent event = WebHook.constructEvent(payload)

Bindambc avatar Apr 19 '23 01:04 Bindambc

Hi, thanks for your work... I need full sample the webhook ?

gustavobrian avatar Jun 03 '23 23:06 gustavobrian