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
138 stars 69 forks source link

WebHookExample #83

Closed eos1d3 closed 2 months ago

eos1d3 commented 1 year ago

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!

github-actions[bot] commented 1 year 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!

pcomp96 commented 1 year ago

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!

eos1d3 commented 1 year ago

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

Bindambc commented 1 year ago

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)
gustavobrian commented 1 year ago

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