Receiving Events - Webhooks
When new messages come into any of your channels or you want to be notified immediately we have any updates on your conversations, we trigger events that your application can listen to. We do this using webhooks.
A webhook is a URL on your server where we send payloads for such events.
You can specify your webhook URL on your Settings page or on individual channels where we would send POST
requests to whenever an event occurs.
Verify Event Origin
Signature
Our event comes with ```x-oneroute-signature``` in the header and you can use this to verify the event is from us and wasn't tampered with. To verify the origin, you can use the below code
const oneRouteSignatureHash = req.headers['x-oneroute-signature']
const hash = crypto.createHmac('sha512', 'OneRoute Secret Key').update(JSON.stringify(req.body)).digest('hex');
if (oneRouteSignatureHash === hash) {
// valid... do something
} else {
// invalid... do something
}
IP whitelisting
With this method, you only allow certain IP addresses to access your webhook URL while blocking out others. OneRoute will only send webhooks from the following IP addresses:
174.138.104.128
Receiving Events
To receive the event, you will have to create an unauthenticated POST
route on your application that returns a 200
status code as it's response.
// Using Express
app.post("/my/webhook/url", function(req, res) {
// Retrieve the request's body
var event = req.body;
// Do something with event
res.send(200);
});
Supported Events
{
"event": "newMessage",
"message": {
"sender": {
"name": "Message Sender",
"authUser": false,
"lastActivity": "2022-01-29T07:27:52.676Z"
},
"externalId": null,
"content": "Hello World!",
"contentType": "TEXT",
"imageUrl": null,
"videoUrl": null,
"documentUrl": null,
"audioUrl": null,
"quoted_message_id": null,
"conversation_id": "bf9d96d9-e495-489a-a22a-206b0ea44d90"
},
"conversation": {
"id": "bf9d96d9-e495-489a-a22a-206b0ea44d90",
"subject": null,
"agent": null,
"customer": {
"name": "Customer name",
"email": "[email protected]"
},
"lastMessageAt": "2022-01-29T07:27:52.793Z",
"status": "in-queue",
"country": "NG",
"read": false,
"createdAt": "2022-01-29T07:18:58.172Z",
"updatedAt": "2022-01-29T07:27:52.794Z",
"agent_id": null,
"Channel": {
"id": "8bad2edc-2973-4cec-8f33-a17c54dc0686",
"phone": null,
"identifier": "Identifier",
"medium": "WHATSAPP",
"credentials": null,
"description": "Whatsapp Channel",
"name": "Channel name",
"type": "CUSTOM",
"provider": null,
"country": "NG",
"env": "LIVE",
"status": "ACTIVE",
"webhookUrl": "https://webhook.url"
}
}
}
WhatsApp Campaign Events
{
"event": "compaignDeliveryReport",
"message": "campaign completed.",
"campaignReportUrl": "https://api.oneroute.io/api/public/logs?page[size]=10&page[number]=1&campaign_id=campaign_id"
"conversation": {
"id": "id",
"firm_id": "firm id"
}
}
Last updated
Was this helpful?