Webhook API
Currently only WhatsApp webhook events are supported

Messages

Connectly supports sending webhook events to your endpoint. Currently, only WhatsApp messages are supported. Before receiving webhook events you need to register your endpoint:
cURL
1
curl --request POST \
2
--url https://api.connectly.ai/v1/businesses/<business_id>/create/webhooks \
3
--header 'Accept: application/json' \
4
--header 'Content-Type: application/json' \
5
--header 'X-API-Key: <YOUR_KEY_HERE>' \
6
--data '
7
{
8
"topic":"messages",
9
"address":"https://example.com/webhook"
10
}]
Copied!
The payload example:
cURL
1
// Headers:
2
{
3
"content-length": "154",
4
"x-connectly-hmac-sha256": "OS/QJB97O/sOj3Ugh4vUJ32EE2++vWq9o51ajIJZwuo=",
5
"user-agent": "go-resty/2.6.0 (https://github.com/go-resty/resty)",
6
"content-type": "text/plain; charset=utf-8",
7
"accept-encoding": "gzip"
8
}
9
// Body
10
{
11
"timestamp": "1639083206",
12
"sender": {
13
"id": "+16315555500",
14
"channelType": "whatsapp",
15
"name": "Vasi from Connectly"
16
},
17
"recipient": {
18
"id": "+16044441234",
19
"channelType": "whatsapp",
20
"name": "connectlyai"
21
},
22
"message": {
23
"text": "TEST 11"
24
},
25
"attachments": [],
26
"location": null
27
}
Copied!
The webhook request header contains HMAC Sha256 to verify that the event comes from Connectly. The HMAC can be found in x-connectly-hmac-sha256. To verify the HMAC:
Go
1
secret := "YOUR_SECRET_VALUE"
2
data := string(webhookEventBody)
3
hash := hmac.New(sha256.New, []byte(secret))
4
_, err := hash.Write(data)
5
if err != nil {
6
return "", err
7
}
8
isValid := webhookEventHMAC == base64.StdEncoding.EncodeToString(hash.Sum(nil)), nil
Copied!
To acknowledge delivery on your end your endpoint needs to reply with 200 response.

Delivery Status

Delivery status events communicate to you the status of the messages that you have sent to your business clients.
Because WhatsApp works not only on the devices that are connected to the internet but on landline phone networks as well there are many cases when the message can fail to reach the final destination. For example, the phone number may not be on WhatsApp, network failures, incorrect message parameters all can result in message delivery failure.
Also, you can understand whether your message was read by the recipient or not.
The status that Connectly sends to you are:
  1. 1.
    sent - the message was dispatched to the recipient. It has not been delivered yet.
  2. 2.
    delivered - the message reached the recipient. It has not been read in the mobile/desktop app. The recipient can read the message from the phone notification though but it will not be registered as read by the recipient's WhatsApp mobile/desktop application.
  3. 3.
    read - the message was read by the recipient within the recipient's WhatsApp mobile/desktop application.
  4. 4.
    delivery_failed - the message failed to reach the recipient. You will be provided with the error code, reason, and trace id that gives the explanation as to why it failed. Please contact Connectly team with the trace id to get more details for the explanation.
  5. 5.
    Register the endpoint against the delivery_status endpoint: https://api.connectly.ai/v1/businesses/<BUSINESS_ID>/create/webhooks with payload:
JSON
1
{
2
"topic":"delivery_status",
3
"address":"<YOUR_ENDPOINT>"
4
}
Copied!
  1. 1.
    You will start receiving the delivery notification events like this:
JSON
1
{
2
"topic": "delivery_status",
3
"timestamp": "1641513098",
4
"sender": {
5
"id": "+16044441234",
6
"channelType": "whatsapp",
7
"name": "connectlyai"
8
},
9
"recipient": {
10
"id": "+16315555500",
11
"channelType": "whatsapp",
12
"name": "Vasi from Connectly"
13
},
14
"statusUpdate": {
15
"id": "01FRRWW2ZAHD9GJ1SWY4VF2GBD",
16
"status": "delivered",
17
"error": null,
18
"metadata": {
19
"campaignName": "connectly_test_campaign"
20
}
21
}
22
}
Copied!
Whenever you create a message through the API (e.g https://api.dev.connectly.ai/v1/businesses/<BUSINESS_ID>/send/messages) you receive back the response created message ID
JSON
1
{"id": "01FRRVK645V350357FGV2Y1B16"}
Copied!
When you receive the delivery notification events for the id in the "statusUpdate": object will match the one in the response of the created message ID. You can tie them this way.
In case of errors the delivery status events look like this:
JSON
1
{
2
"topic": "delivery_status",
3
"timestamp": "1641512856",
4
"sender": {
5
"id": "+16044441234",
6
"channelType": "whatsapp",
7
"name": "connectlyai"
8
},
9
"recipient": {
10
"id": "+16315555500",
11
"channelType": "whatsapp",
12
"name": "Vasi from Connectly"
13
},
14
"statusUpdate": {
15
"id": "01FRRWMSAMKNFZAMBPQ65CA7DD",
16
"status": "delivery_failed",
17
"error": {
18
"message": "Message template inputs invalid",
19
"type": "ERROR_TYPE_INVALID_REQUEST",
20
"code": "ERROR_CODE_MESSAGE_TEMPLATE_INPUT_INVALID",
21
"userTitle": "Message template inputs invalid",
22
"userMessage": "Pass along the connectly trace id 'cnct_trace_id' to the team for more information.",
23
"cntTraceId": "10827968052975079261",
24
"details": {
25
}
26
}
27
}
28
}
Copied!
This should help when you send the WhatsApp template messages to understand whether they reached the final destination or not. You send WhatsApp templated message, you get back the message ID, you store it in your system and get back the delivery status event with that message ID saying if it was sent/delivered/delivery_failed/read
Copy link