Webhooks
So that you receive notifications of events related to your domain users and messages.
Since your domain users and messages are stored in our databases. Callbacks URLs are used to synchronize data stored in our servers with data stored in your database. They also allow you to do custom backgroud tasks when chat events happened such as user status change, sending message, receiving message etc...
You can retrieve your domain users presence status in real time through the use of a Callback URL. You can then save user's presence status in your database or show the list of online users in your website or filter users by presence status.
The feature is not enabled by default, to activate it you must define a valid callback URL and enable feature in your admin panel.
Once activated, for each change of user presence status, our MQTT servers send to the Callback URL this JSON data:
Variable Name | Description |
userid | data-user-id of user |
status | new user presence status |
timestamp | unix timestamp of last user presence status |
Below an example in PHP page https://www.votre-domain.com/status-callback.php that retrieves json data sent by MQTT chat.
/* get JSON Post Data */
$json = file_get_contents('php://input');
/* get PHP data Array */
$data = json_decode($json);
/* show userid and status */
echo $data["userid"].":".$data["status"];
$json
content example :{
"userid":1,
"status":"online",
"timestamp":1602512800
}
During a hardware failure or unexpected shutdown of an MQTT node. Presence system is reseted. This operation is done automatically on MQTT servers side. on your side it is also necessary to reset the state of presence of your users.
When resetting the presence system, our MQTT servers send the JSON data below to your status callback URL.
{
"userid":0,
"status":"offline",
"timestamp":1602511574
}
When you receive json data withuserid
equal to zero, means that you must reset your user's status in your database and therefore assign offline status to all your users.D'ont worry this will not affect presence status of your users since presence system will rebuild itself again in no time.🧐😉For example below how to do in PHP:
if($data["userid"]==0){
$mysqli->query("update users set status='offline'");
}else{
$mysqli->query("update users set status='".$data["status"]."' where id=".$data["userid"]);
}
To receive real-time notifications whenever a message is sent by users in your domain. You must activate a Callback URL to your website. The feature is not enabled by default, to activate it you must define a valid callback URL and enable feature in your admin panel.
Once activated, for each new message sent, our MQTT servers send to the Callback URL this JSON data.
Variable Name | Description |
from_userid | userid of user who send the message |
to_userid | userid of user who receive the message |
#message | message content |
Message data :
Variable Name | Description |
id | message id |
message | message value |
timestamp | unix timestamp |
type | message type |
p1 | Parameter 1 |
p2 | Parameter 2 |
P3 | Parameter 3 |
Message Type:
Variable Value | Description |
0 | Text & smileys |
1 | Stickers |
2 | Picture from disk |
3 | Record |
4 | Picture from cam |
5 | Audio/Video Notification |
Below an example in PHP page https://www.votre-domain.com/messages-callback.php that retrieves json data sent by MQTT chat.
$json = file_get_contents('php://input');
/* get PHP data Array */
$data = json_decode($json);
$data
content example :{
"from_userid":2,
"message":{
"id":138946,
"message":"ok",
"p1":"",
"p2":"",
"p3":"",
"timestamp":1602511586,
"type":0
},
"to_userid":3601
}
When adding a callback URL, you should add a valid URL reachable by internet. Adding a mal formed or inaccessible URL can cause timeouts and overload of our servers. For this we have planned to disable immediately any callback URL which returns non-reachability or HTTP response codes 401, 403 etc . In this case you must reactivate feature again with a valid URL this time.
In all cases you can supervise last data sets or errors related to yours callback URLs through logs availables in your admin panel.