Table of Contents
Introduction #
Webhooks are one of the most useful tools in our platform. It helps developers and site owners to listen for events from the devices or WhatsApp server, so it is a useful tool when creating automated tasks.
This function is strictly for incoming events only, sms received , WhatsApp chat read; ussd responded to and android notifications.
Use Cases #
- Create an autoreply bot for SMS and WhatsApp.
- Save messages and chats to your own database on receive.
- Save notifications to your own database on receive.
- Save USSD responses to your own database on receive.
- Send the payload to the specified email addresses.
- Send an SMS/Chat when you get a notification from Facebook.
- Do something when you get a notification from an app.
How It Works #
The system receives an event from both sources and then the webhook url will be called with payload data being sent. When your webhook server gets it, you can do anything with the payload yourself. Payloads are delivered by a request method POST.
Payload Structure #
The payload structure is straightforward; you just need to check the type of payload and then process the content of the data body.
SMS #
[
"type" => "sms", // type of payload: received sms
"data" => [
"id" => 2, // unique id from the system
"rid" => 10593, // unique id from the device
"sim" => 1, // sim card slot
"device" => "00000000-0000-0000-d57d-f30cb6a89289", // device unique id
"phone" => "+639760713666", // sender phone number
"message" => "Hello World!", // message
"timestamp" => 1645684231 // receive timestamp
]
]
WhatsApp #
[
"type" => "whatsapp", // type of payload: received whatsapp chat
"data" => [
"id" => 2, // unique id from the system
"wid" => "+639760713666", // whatsapp account phone number
"phone" => "+639760666713", // sender phone number
"message" => "Hello World!", // message
"attachment" => "http://imageurl.com/image.jpg", // attachment url
"timestamp" => 1645684231 // receive timestamp
]
]
USSD #
[
"type" => "ussd", // type of payload: received ussd response
"data" => [
"id" => 98, // unique id from the system
"sim" => 1, // sim card slot
"device" => "00000000-0000-0000-d57d-f30cb6a89289", // device unique id
"code" => "*143#", // ussd code
"response" => "Sorry! You are not allowed to use this service.", // ussd response
"timestamp" => 1645684231 // receive timestamp
]
]
notification #
[
"type" => "notification", // type of payload: received notification
"data" => [
"id" => 77, // unique id from the system
"device" => "00000000-0000-0000-d57d-f30cb6a89289", // device unique id
"package" => "com.facebook.katana", // application package name
"title" => "Someone commented on your post!", // notification title
"content" => "Someone commented on your post!", // notification content
"timestamp" => 1645684231 // receive timestamp
]
]
Code Example #
<?php
$request = $_REQUEST;
$secret = "WEBHOOK_SECRET"; // you can obtain this from (Tools -> Webhooks)
/**
* Validate webhook secret
*/
if(isset($request["secret"]) && $request["secret"] == $secret):
// Valid webhook secret
$payloadType = $request["type"];
$payloadData = $request["data"];
// do something with the payload
print_r($payloadType);
print_r($payloadData);
else:
// Invalid webhook secret
endif;