Home > Developers > Documentation > MQTTCHAT SDKs

MQTTCHAT SDKs version 1.0.0

Since you do not have direct access to our database, 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 SDk in the programming languages currently available: php and Android.

Before you can use the SDk, you must install it in the environment in which you want to use it.

You can install php sdk using two methods:

  • Using PHP composer:
  • 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
  • Download latest release from Github repository and extract the zip content in your website root path.
  • 1- Add MQTTCHAT Artifactory repository to the list of Maven repositories in your top level build.gradle file:
     
    allprojects {
        repositories {       
            maven {
                url "http://mqttchat.telifoun.com:8081/artifactory/libs-release-local"
                credentials {
                    username = "mqttchat"
                    password = "telifoun"
                }
            }
        }
    }   
                        
    2-You can then simply add MQTTCHAT core artifacts as a dependencies in the build.gradle file of your main project:
    
    dependencies {
        implementation 'com.telifoun.mqttchat:mqttchat-core:1.1.0'
    }       
    
    

    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.

    You should add theses two parameters to config file of your SDK located at : src/telifoun/mqttchat/config.php.

                       
        namespace telifoun\mqttchat; 
        class config{     
        /** telifoun mqttchat app_id **/
        const APP_ID="mqttchat-xxxxxxxx";
        /** telifoun mqttchat app_secret **/
        const APP_SECRET="mqttchat-xxxxxxxxxxxxxxxx";
    
        /** telifoun mqttchat rest server **/
        const MQTTCHAT_REST_SERVER="http://cluster1.telifoun.com/rest" ;    
    
        /* .... */  
        }              

    To use the android sdk, you must first init the sdk singleton class, preferably in the Application class of your Android Application.

    You can do this in two ways:

  • Initialize sdk only :
  •         
        new sdk.getBuilder()
               .context(this.getContext())
               .restServerUrl("http://cluster1.telifoun.com")
               .appId("mqttchat-xxxxxxxx")
               .appSecret("mqttchat-xxxxxxxxxxxxxxxx")
               .debugMode(true)
               .build();
                    
  • Initialize mqttchat, the initialization of sdk will be done indirectly through the initialization of mqttchat singleton class. Please see MQTTCHAT Android documentation for more information

  • Add 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"];
    }
                    
      
    sdkUser user =new sdkUser();
    user.Set(1,"user name","user surname","profile_link","avatar_link",0);
    user.Add(new sdkCallback() {
       @Override
       public void OK(RestResponse restResponse) {
          Log.i(Tag,restResponse.getData());
       }
       @Override
       public void KO(RestResponse restResponse) {
         Log.e(Tag,restResponse.getError().getError());
       }
    });             

    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();    
                    
      
    sdkUser user =new sdkUser();
      user.setUserId(1);
      user.setAvatar_link("avatar link");  
      user.Update(new sdkCallback() {
      @Override
       public void OK(RestResponse restResponse) {
          Log.i(Tag,restResponse.getData());
       }
       @Override
       public void KO(RestResponse restResponse) {
         Log.e(Tag,restResponse.getError().getError());
       } 
    });     
    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();
                    
      
    sdkUser user =new sdkUser();
      user.setUserId(1); 
      user.Get(new sdkCallback() {
       @Override
       public void OK(RestResponse restResponse) {
          Log.i(Tag,restResponse.getData());
       }
       @Override
       public void KO(RestResponse restResponse) {
         Log.e(Tag,restResponse.getError().getError());
       }
    });     

    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();
                    
      
    sdkUser user =new sdkUser();
      user.setUserId(1); 
      user.Remove(new sdkCallback() {
       @Override
       public void OK(RestResponse restResponse) {
          Log.i(Tag,restResponse.getData());
       }
       @Override
       public void KO(RestResponse restResponse) {
         Log.e(Tag,restResponse.getError().getError());
       }  
    });       

    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.


    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']){
    }
                    
      
    sdkUser user =new sdkUser();
      user.setUserId(1); 
      user.friendWith(2,new sdkCallback() {
       @Override
       public void OK(RestResponse restResponse) {
          Log.i(Tag,restResponse.getData());
       }
       @Override
       public void KO(RestResponse restResponse) {
         Log.e(Tag,restResponse.getError().getError());
       }
    });       

    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']){
    }
                    
      
    sdkUser user =new sdkUser();
      user.setUserId(1); 
      user.notFriendWith(2,new sdkCallback() {
       @Override
       public void OK(RestResponse restResponse) {
          Log.i(Tag,restResponse.getData());
       }
       @Override
       public void KO(RestResponse restResponse) {
         Log.e(Tag,restResponse.getError().getError());
       }
    });       

    To check if a user is friend with a contact

             
    require_once vendor/autoload.php;
    $user=new telifoun\mqttchat\user();
    $user->_setUserid(1);
    $result=$user->is_Friend_With(2);
    if($result['ok']){
    }
                    
      
    sdkUser user =new sdkUser();
      user.setUserId(1); 
      user.isFriendWith(2,new sdkCallback() {
       @Override
       public void OK(RestResponse restResponse) {
          Log.i(Tag,restResponse.getData());
       }
       @Override
       public void KO(RestResponse restResponse) {
         Log.e(Tag,restResponse.getError().getError());
       }
    });    

    2020 © Telifoun.MQTTCHAT Inc.