How to set up a webhook for your WhatsApp updates

In this article you will learn how to set up a webhook to receive Real Time Updates for your WhatsApp Broadcasts and all Whatsapp Updates for your standard conversations.

For any doubt on how to connect you WhatsApp Business account with Tiledesk and how perform WhatsApp Broadcasts, please refer to the following guides:

 

Receive Real Time Update for a WhatsApp Broadcast

After starting a broadcast operation, you can receive all updates regarding it. Tiledesk will send these updates automatically, so you just need to create your own webhook endpoint and subscribe to the correct event.

Login to Tiledesk Dashboard, select a project and go to Settings → Project Settings → Developer → Manage Webhook.

Then click on Add Subscription to create a new subscription. 

Select from the dropdown menu the event ‘Event Emit', type your webhook endpoint address and click on Create Subscription.

 

From now on you will receive all events on your webhook.

In order to discriminate the events that concern a broadcast, simply add on your webhook the following code:

app.post('/hook', async (req, res) => {
	if (req.body?.payload?.name === "tiledesk.whatsapplog") {
    	let whatsapp_log = req.body.payload.attributes?.messageLog;
    	console.log(whatsapp_log);
  	}
});

👉 Check out the Public example on Glitch 

 

Receive all updates from WhatsApp

Similarly to the previous case,  the only thing you need is to create your own webhook endpoint and subscribe to the correct event.

Again, login to Tiledesk Dashboard, select a project and go to Settings → Project Settings → Developer → Manage Webhook.

Then click on Add Subscription to create a new subscription. 

Select from the dropdown menu the event ‘Event Emit', type your webhook endpoint address and click on Create Subscription. Feel free to choose the same endpoint then before or a new one. Just be careful how to discriminate this type of event on your webhook, for which you will have to follow the following code:

app.post('/hook', async (req, res) => {
 	if (req.body?.payload?.name === "tiledesk.whatsappfw") {
    	let whatsapp_body = req.body.payload.attributes?.whatsappBody;
    	console.log(whatsapp_body);
  	}
});

👉 Check out the Public example on Glitch 

 

If you have any questions, feel free to contact us live on chat or at support@tiledesk.com 📧 

For more info on who we are, what we do, or what is our shtick, visit the Tiledesk Website 👩‍🚀