MQTT Notifications
Managing notifications.
As a developer, in some cases, you need to send real-time notifications to users following events or actions according to your application logic. For example when a user sends a friend request to another user. The latter must receive an instant notification to approve or deny the request without waiting to refresh the page or re-open the Android application.
MQTT notifications should not be confused with WEB push notifications or android FCM notifications. MQTT notifications are sent using the socket connection established between the android application or the WEB browser and our MQTT server. No intermediary server is used.

Sending Notification

An MQTT notification is made up of the following fields:
Name
Description
userid
id of user that will receive the notification (mandatory)
title
Notification title (mandatory)
content
Notification content : text or html (mandatory)
icon
Url of image or photo to show (optional)
data
JSON additional data for your application need (optional)
For example to send Notification using PHP SDK.
PHP
1
require_once vendor/autoload.php;
2
3
$post_data=array("userid":1,
4
"title":"friend Request",
5
"content":"John Doe sent you a friend request",
6
"icon":"https://mqtt-chat.com/photos/12542565.png",
7
"data":"{\"param1\":1,\"param2\":2}");
8
9
$n=new telifoun\mqttchat\notifications();
10
$result=$n->add($post_data);
Copied!
1
{
2
"ok": true,
3
"data": {
4
"notification_id": 8555
5
}
6
}
Copied!

Get Notification

You can get already sent notification content by id.
1
require_once vendor/autoload.php;
2
3
$notification_id=8555;
4
5
$n=new telifoun\mqttchat\notifications();
6
$result=$n->get($notification_id);
Copied!
Last modified 2mo ago