How to track Template Messages using Webhooks

Jahnavi Prasad Updated by Jahnavi Prasad

Use case: All template messages sent using the WATI's Send Template Message API Endpoint must be tracked when they were sent, delivered, read, and received a reply.

How To: With the sendTemplateMessage V2 endpoint, whenever a message is triggered, a localMessageId is returned as part of the API response.

Sample cURL request:

curl --location 'https://live-server-123.wati.io/api/v2/sendTemplateMessage?whatsappNumber=<whatsappNumber>' \ 
--header 'Authorization: Bearer <Token>' \
--header 'Content-Type: application/json-patch+json' \
--data '{
"template_name": "update_for_you",
"broadcast_name": "JPTestBroadcast",
"parameters": []
}'

Sample Response:

{ 
"result": true,
"error": null,
"templateName":
"update_for_you",
"receivers": [
{
"localMessageId": "d38f0c3a-e833-4725-a894-53a2b1dc1af6",
"waId": "<whatsappNumber>",
"isValidWhatsAppNumber": true,
"errors": []
}
],
"parameters": []
}

The localMessageId can be used to track the message life cycle in the following Webhook events.

Go to WATI Dashboard -> Webhooks -> Add Webhook -> Paste your webhook URL here. Set Status as Enabled, and choose the following Events:

1) Template Message Sent v2

This webhook is triggered when the Template message is sent and will also contain the localMessageId

Sample payload for this webhook:

{ 
"eventType": "templateMessageSent_v2",
"localMessageId": "d38f0c3a-e833-4725-a894-53a2b1dc1af6",
"id": "640c8fd48b67615f886237b8",
"whatsappMessageId": "gBEGkXmJQZVJAgkRHwjjZsITS6M",
"templateId": "63766ae83b2e064905789c63",
"templateName": "update_for_you",
"created": "2023-03-11T14:27:32.9655388Z",
"conversationId": "639c34fbd205f79bdec81bea",
"ticketId": "640c8e6d8b67615f886237a7",
"text": "Hi! We have an update for you.",
"operatorEmail": "hello@wati.io",
"waId": "<whatsappNumber>",
"type": "template",
"statusString": "SENT",
"sourceType": "API"
}
2) Sent Message is DELIVERED v2

This webhook is triggered when the message you sent is delivered to the user.

Sample payload for this webhook:

{ 
"eventType": "sentMessageDELIVERED_v2",
"statusString": "Delivered",
"localMessageId": "d38f0c3a-e833-4725-a894-53a2b1dc1af6",
"id": "640c8fd48b67615f886237b8",
"whatsappMessageId": "gBEGkXmJQZVJAgkRHwjjZsITS6M",
"conversationId": "639c34fbd205f79bdec81bea",
"ticketId": "640c8e6d8b67615f886237a7",
"text": null,
"type": "template",
"timestamp": "1678544854",
"assigneeId": null,
"operatorEmail": "hello@wati.io"
}
3) Sent Message is READ v2

This webhook is triggered when the message you sent is read by the user.

Sample payload for this webhook:

{ 
"eventType": "sentMessageREAD_v2",
"statusString": "Read",
"localMessageId": "d38f0c3a-e833-4725-a894-53a2b1dc1af6",
"id": "640c8fd48b67615f886237b8",
"whatsappMessageId": "gBEGkXmJQZVJAgkRHwjjZsITS6M",
"conversationId": "639c34fbd205f79bdec81bea",
"ticketId": "640c8e6d8b67615f886237a7",
"text": null,
"type": "template",
"timestamp": "1678545043",
"assigneeId": null,
"operatorEmail": "hello@wati.io"
}
4) Sent Message is REPLIED v2

This webhook is triggered when the user replies back to the message you sent

Sample payload for this webhook:

{ 
"eventType": "sentMessageREPLIED_v2",
"statusString": "Replied",
"localMessageId": "d38f0c3a-e833-4725-a894-53a2b1dc1af6",
"id": "640c8fd48b67615f886237b8",
"whatsappMessageId": "gBEGkXmJQZVJAgkRHwjjZsITS6M",
"conversationId": "639c34fbd205f79bdec81bea",
"ticketId": "640c8e6d8b67615f886237a7",
"text": null,
"type": "template",
"timestamp": "1678545074",
"assigneeId": null,
"operatorEmail": "hello@wati.io"
}

How did we do?

Are your file attachment names appearing as null or untitled?

Contact