Skip to content
MQTT CHAT PHP SDK
PHP
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
nbproject
src/telifoun/mqttchat
vendor
.gitignore
README.md
composer.json
composer.lock

README.md

mqttchat-php-sdk

Introduction

Since you do not have direct access to MQTTCHAT databases, you need an SDK as an intermediary to add your users to MQTTCHAT, edit user's informations etc ... The SDK is based on calls to REST services hosted on our web servers. All queries are authenticated using OAuth2 protocol.
In this documentation we will see differents operations you can do with mqttchat PHP SDk.

Setup

Before you can use the SDk, you must install it using PHP Composer or download latest release from this repository and extract it in your website root directory.
The easiest way is to use php Composer,you should first install php composer software then install the sdk using this command line.

composer require med_aboub/mqttchat-php-sdk

Configuration

You must now get your REST authentication parameters App_ID and APP_secret wich are specific to each domain and are necessary to authenticate with REST services.
To obtain them, you must first create MQTTCHAT account then activate a free or paied subscription for your domain. Once activation is successful, you will receive in your client area (settings tab) the two parameters App_ID and APP_secret.
yous should add theses two parameters to config file of your SDK located at : src/telifoun/mqttchat/config.php

<?php
namespace telifoun\mqttchat; 
 class config{     
    /** telifoun mqttchat app_id **/
    const APP_ID="mqttchat-xxxxxxxx";
    /** telifoun mqttchat app_secret **/
    const APP_SECRET="mqttchat-xxxxxxxxxxxxxxxx";  
}    

Users Management

Add new user

Adding a new user to MQTTCHAT is done in two steps: first define user basic informations with Set function then add it to your domain users list using Add function.

require_once vendor/autoload.php;
$user=new telifoun\mqttchat\user();
$user->Set(1,"name","surname","profile_link","avatar_link",telifoun\mqttchat\user::GENDER_MALE);
$result=$user->Add();
if ($result["ok"]){
var_dump($result["response"]);
}else{
echo $result["response"]["error"];
}

If you don't like to add profile link or avatar link keep fields empties to be ignored.

Edit user

To edit existing user information’s, you should define the userid , informations to update then call Update function.

require_once vendor/autoload.php;
$user=new telifoun\mqttchat\user();
$user->_setUserid(1);
$user->_setAvatarLink("http://www.exemple.com/images/avatar_men2.png");
$user->_setName("Foulen 2");
$result=$user->Update();    

And to verify that user information’s are changed, you can use Get function. Do not forget to specify user userid before.

require_once vendor/autoload.php;
$user=new telifoun\mqttchat\user();
$user->_setUserid(1);
$result=$user->Get();

Remove user

If you want to delete a user, the Remove function is made for that.

require_once vendor/autoload.php;
$user=new telifoun\mqttchat\user();
$user->_setUserid(1);
$result=$user->Remove();

Friends management

If you do not use the notion of friends between users, you can skip this section. Since the concept of friends is an MQTTCHAT option for dating or social networks websites.
If friends option is enabled, all MQTTCHAT features will be limited to the friends list. Else user can browse the list of all users and can chat with any one.
Please see MQTTCHAT Documentation for more informations about this.

Add a new contact to friends list

To add a new friend to a user friends list:

require_once vendor/autoload.php;
$user=new telifoun\mqttchat\user();
$user->_setUserid(1);
$result=$user->friend_With(2);
if($result['ok']){
}

To check if two users are friends:

require_once vendor/autoload.php;
$user=new telifoun\mqttchat\user();
$user->_setUserid(1);
$result=$user->is_Friend_With(2);
if($result['ok']){
}

Remove contact from friends list

require_once vendor/autoload.php;
$user=new telifoun\mqttchat\user();
$user->_setUserid(1);
$result=$user->not_Friend_With(2);
if($result['ok']){
}
You can’t perform that action at this time.