OneRoute
  • Introduction
  • Prerequisites
  • Whatsapp API
    • Sandbox (Test API Key)
    • Getting Started
    • Endpoints
      • Fetch Channels
      • Fetch Channel Templates
      • Send Template Message
      • Send Campaign Message
      • Send Session Message
    • FAQ
  • EMAIL API
    • Getting Started
    • Endpoints
      • Fetch Email Channels
      • Send Email to Customers
  • SMS API
    • Getting Started
    • Endpoints
      • Fetch SMS Channels
      • Send SMS to Customers
      • Send OTP SMS to Customers
      • Fetch SMS Messages
      • Get SMS DLR Message
  • ONEOTP API
    • Getting Started
    • Endpoints
      • Fetch OTP Templates
      • Send OTP
      • Verify OTP
  • EMBED
    • Getting Started
    • Installation
    • Push Notification
  • OTHERS
    • Receiving Events - Webhooks
    • Fetch Channel By Id
    • Fetch Logs
Powered by GitBook
On this page
  • Verify Event Origin
  • Receiving Events
  • Supported Events
  • WhatsApp Campaign Events

Was this helpful?

  1. OTHERS

Receiving Events - Webhooks

PreviousPush NotificationNextFetch Channel By Id

Last updated 2 months ago

Was this helpful?

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 or on individual channels where we would send POST requests to whenever an event occurs.

Kindly ensure your webhook URL is publicly available (localhost URLs cannot receive events).

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:

  1. 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);
});
<?php
// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event = json_decode($input);
// Do something with $event
http_response_code(200); // PHP 5.4 or greater
?>

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": "customer@mail.com"
    },
    "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"
    }
  }
}
{
    "event": "lowUnitBalance",
    "firm": "Firm Name",
    "units": 0 // remaining unit balance
}
{
    "event": "otpVerified",
    "id": "12345678904",
    "otp": "12345",
    "identifier": "key",
    "expiration_time": "2022-01-29T07:27:52.676Z",
    "createdAt": "2022-01-22T07:27:52.676Z",
    "verified": true
}
{
    "event": "smsDeliveryReport",
    "message": null,
    "conversation": {
        "id": "1234567",
        "externalId": "1234567890",
        "status": "delivered",
        "reason": "Message delivered to handset",
        "from": "Name",
        "to": "12345678",
        "units": 0,
        "delivered_time": "2023-08-29T08:18:31.732Z",
        "createdAt": "2023-08-29T08:18:28.576Z"
    }
}

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"
    }
}
{
    "event": "whatsappDeliveryReport",
    "message": null,
    "conversation": {
        "id": "iodsjiohsduihys7ywwy8oisd",
        "externalId": "iusdiywy78wt6stfauahiu",
        "status": "read",
        "reason": null,
        "from": "234879927352",
        "to": "+23480634279362",
        "units": 0,
        "delivered_time": "2024-12-04T13:49:05.000Z",
        "template_category": "MARKETING",
        "createdAt": "2024-12-04T13:47:23.000Z",
        "campaign_id": "982376327jiadnkjddxtdd",
        "identifier": "f1005383-7d8d-4351"
    }
}
{
    "count": 2,
    "data": [
        {
            "id": "uiwyytw8728928ujd",
            "externalId": "isjdoijui87w6e7iousiojiosdus",
            "status": "read",
            "reason": null,
            "from": "2348183625392",
            "to": "+234808376725898",
            "units": 0,
            "delivered_time": "2024-12-04T13:49:05.000Z",
            "createdAt": "2024-12-04T13:47:23.000Z",
            "campaign_id": "8932789ujksdmkiosuydw78",
            "identifier": "f1005383-7d8d-4351"
        },
        ...
    ],
    "currentPage": 1,
    "totalPage": 1,
    "message": "logs data",
    "success": true
}
Settings page