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...

Users Presence callback URL

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.
Mqttchat Telifoun - Set status callback URL
iorad
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.
1
/* get JSON Post Data */
2
$json = file_get_contents('php://input');
3
4
/* get PHP data Array */
5
$data = json_decode($json);
6
7
/* show userid and status */
8
echo $data["userid"].":".$data["status"];
9
Copied!
$json content example :
1
{
2
"userid":1,
3
"status":"online",
4
"timestamp":1602512800
5
}
Copied!

Status Reset

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.
1
{
2
"userid":0,
3
"status":"offline",
4
"timestamp":1602511574
5
}
Copied!
When you receive json data with userid 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:
1
if($data["userid"]==0){
2
$mysqli->query("update users set status='offline'");
3
}else{
4
$mysqli->query("update users set status='".$data["status"]."' where id=".$data["userid"]);
5
}
Copied!

Messages CallBack URL

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.
Mqttchat Telifoun - Messages Callback URL
iorad
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.
1
$json = file_get_contents('php://input');
2
3
/* get PHP data Array */
4
$data = json_decode($json);
5
Copied!
$data content example :
1
{
2
"from_userid":2,
3
"message":{
4
"id":138946,
5
"message":"ok",
6
"p1":"",
7
"p2":"",
8
"p3":"",
9
"timestamp":1602511586,
10
"type":0
11
},
12
"to_userid":3601
13
}
Copied!

Logs

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.
Mqttchat Telifoun - Webhooks Logs
iorad
Last modified 2mo ago