Skip to main content

Create a new webhook subscription

Posting a request to this endpoint will create a new webhook subscription to the specified event.

List of accepted events

Any of these events can be specified as a query parameter in the invocation URL.

info

Check out some of the payload examples.

EventDescription
whatsapp.call.receivedTriggers when a new WhatsApp call is received and missed.
whatsapp.message.newTriggers when a new WhatsApp message is either sent or received
whatsapp.message.receivedTriggers when a new WhatsApp message is received. Example.
whatsapp.order.receivedTriggers when a new WhatsApp order is received. Example.
whatsapp.message.sentTriggers when a new WhatsApp message is sent. Example.
whatsapp.conversation.newTriggers when a new WhatsApp conversation is started
whatsapp.audio.transcribedTriggers when a new WhatsApp audio message is transcribed to text
whatsapp.message.reactionTriggers when someone reacts to a message. Example.
whatsapp.message.editedTriggers when a message is edited. Example.
info

If you want to capture these events only for a specific group, use the to_group_uuid parameter.

EventDescription
whatsapp.group.message.receivedTriggers when a message is received on a WhatsApp group your number is part of.
whatsapp.group.message.reactionTriggers when a group participant reacts to a message.
whatsapp.group.joinTriggers when someone joins a group.
whatsapp.group.leaveTriggers when someone leaves a group.
whatsapp.group.removeTriggers when someone is kicked/removed from a group.

WhatsApp message receipt events:

info

it's important to consider that 2Chat can only see messages arriving after the time you connected your number to our service. Messages that arrived prior to this connection are not visible to us.

EventDescription
whatsapp.message.receipt.sentTriggers when a message you sent is in the process of being delivered to the receiver.
whatsapp.message.receipt.receivedTriggers when a message you sent is received on the app of its intended receiver.
whatsapp.message.receipt.readTriggers when the receiver reads a message you sent, provided the receiver has read-receipts enabled. Example.

WhatsApp number status events:

EventDescription
whatsapp.number.statusTriggers when a WhatsApp number you connected to 2Chat changes status. E.g.: ready (connected), disconnected, qr-received, loading, etc. Example.
tip

In the case of qr-received event, you can also obtain the latest QR code value using the Get QR Code Endpoint.

Parameters

info

These parameters should be sent as JSON payload in the request body.

FieldDescription
hook_urlA valid and publicly reachable URL that 2Chat will invoke when the event is triggered
on_numberThe phone number that you have configured and connected to 2Chat. Always make sure it is connected
time_periodRequired only if you are subscribing to whatsapp.conversation.new.

For the whatsapp.conversation.new event, you can specify also the time period of your preference to consider a conversation new.

Time Period ValueDescription
all-timeWill trigger the new conversation event when the user messages you for the first time ever. This is the default value when no time period is specified
hourWill trigger the new conversation event after 1 hour of no messages
dayWill trigger the new conversation event after 1 day of no messages
weekWill trigger the new conversation event after 1 week of no messages
monthWill trigger the new conversation event after 1 month of no messages
yearWill trigger the new conversation event after 1 year of no messages

Filtering events on WhatsApp groups

For any of the group-related events, such as whatsapp.group.message.reaction, you can restrict the triggering of events by passing an extra payload parameter that will make the webhook only be called when the event occurs on the configured group.

FieldDescription
to_group_uuidUUID of the group where the event should trigger to call your webhook. By default, its value is any and will trigger for the event happening on any of your WhatsApp groups.

Invocation

Assume we want to subscribe to the event whatsapp.message.received as example:

curl --location --request POST 'https://api.p.2chat.io/open/webhooks/subscribe/whatsapp.message.received' \
--header 'X-User-API-Key: your_api_key_here' \
--header 'Content-Type: application/json' \
--data-raw '{
"hook_url": "https://www.toptal.com/developers/postbin/1681755466939-3421728690154",
"on_number": "+595981048477"
}'

Response

The API will return a the newly configured webhook if successful.

{
"success": true,
"data": {
"uuid": "WHK530c9d58-2259-4ce2-82a8-1941f3a60665",
"event_name": "whatsapp.message.sent",
"channel_uuid": "WPN95841312-b54d-46e3-b0bc-6414f4a5296b",
"hook_url": "https://www.toptal.com/developers/postbin/1681755466939-3421728690154",
"hook_params": {
"waweb_uuid": "WPN95841312-b54d-46e3-b0bc-6414f4a5296b"
},
"created_at": "2023-04-18T01:58:02Z"
}
}
FieldDescriptionExample values
uuidThe unique identifier of the webhook that you will need to make changes to itWHK530c9d58-2259-4ce2-82a8-1941f3a60665
event_nameThe name of the event this webhook is subscribed towhatsapp.message.sent
channel_uuidThe unique UUID of the channel this webhook is subscribed toWPN95841312-b54d-46e3-b0bc-6414f4a5296b
hook_urlThe URL 2Chat will call when a event is triggeredhttps://www.toptal.com/develop...
hook_paramsCustom parameters 2Chat sets to make the webhook functional{"waweb_uuid": "WPN95841312-b54d-46e3-b0bc-6414f4a5296b"}
created_atUTC timestamp for when the webhook was created2023-04-18T01:58:02Z