Getting Started Guide

Configure Tokens and Run Sample App

We are now ready to configure the app with user access tokens and run it. We'll first briefly understand the initialization code, then run the app, all in just 4 steps:

Before proceeding further:

  1. Download the source code of the app in this tutorial from the mesibo GitHub repositoriesopen_in_new.
  2. Open it in your IDE (Android Studio, Xcode etc). Follow along as you go through this tutorial.

Step 1: Setup mesibo listeners

Since your app can receive messages and calls anytime and asynchronously, you should define listeners and instruct mesibo to call them immediately when any event occurs. mesibo invokes these listeners to notify your app about events like incoming messages, calls, connection status changes etc. For example,

  • when a message is received, Mesibo_OnMessage will be called
  • when a message is sent, delivered, or read Mesibo_OnMessageStatus will be called
  • when a call is received MesiboCall_OnIncoming will be called
  • when your app goes online or offline Mesibo_OnConnectionStatus will be called
  • And so on...

You can create listeners by creating a class that implements various mesibo listener interfaces, as shown in the example code below for different programming languages. Refer to the app source code for more details.


Complete code on GitHub for Javaopen_in_new

@Override
public void Mesibo_onConnectionStatus(int status) {
    // You will receive the connection status here
    Log.d(TAG, "on Mesibo Connection: " + status);
}

@Override
public void Mesibo_onMessage(MesiboMessage msg) {  
    // You will receive messages here
}

@Override
public void Mesibo_onMessageUpdate(MesiboMessage msg) {  
    // You will receive message updates here
}

@Override
public void Mesibo_onMessageStatus(MesiboMessage msg) {
    // You will receive status of sent messages here
}

Complete code on GitHub for Kotlinopen_in_new,

override fun Mesibo_onConnectionStatus(status: Int) {
    // You will receive the connection status here
}

override fun Mesibo_onMessage(message: MesiboMessage) {
    // You will receive messages here
}

override fun Mesibo_onMessageUpdate(message: MesiboMessage) {
    // You will receive message updates here
}

override fun Mesibo_onMessageStatus(message: MesiboMessage) {
    // You will receive the status of sent messages here
} 

Complete code on GitHub for Swiftopen_in_new

public func Mesibo_onConnectionStatus(status: Int) {
    // You will receive the connection status here
}

func Mesibo_onMessage(message: MesiboMessage) {
    // You will receive messages here
}

func Mesibo_onMessageUpdate(message: MesiboMessage) {
    // You will receive message updates here
}


func Mesibo_onMessageStatus(message: MesiboMessage)
    // You will receive the status of sent messages here 
}   

Complete code on GitHub for Objective-Copen_in_new

-(void) Mesibo_onConnectionStatus:(NSInteger)status {
    // You will receive the connection status here
    NSLog(@"Connection status: %d", status);
}

-(void) Mesibo_onMessage:(MesiboMessage *)msg {
    // You will receive messages here
}

-(void) Mesibo_onMessageUpdate:(MesiboMessage *)msg {
    // You will receive message updates here
}

-(void) Mesibo_onMessageStatus:(MesiboMessage *)msg {
    // You will receive the status of sent messages here 
}   

Complete code on GitHub for Flutteropen_in_new

@override
void Mesibo_onConnectionStatus(int status) {
    print('Mesibo_onConnectionStatus: ' + status.toString());
}

@override
void Mesibo_onMessage(MesiboMessage message) {
    // You will receive messages here
}

@override
void Mesibo_onMessageUpdate(MesiboMessage message) {
    // You will receive message updates here
}

@override
void Mesibo_onMessageStatus(MesiboMessage message) {
    // You will receive the status of sent messages here 
}

Complete code on GitHub for JavsScriptopen_in_new

MesiboListener.prototype.Mesibo_onConnectionStatus = function(status, value) {
    console.log("Mesibo_onConnectionStatus: "  + status);
}


MesiboListener.prototype.Mesibo_onMessage = function(m) {
    // You will receive messages here
}

MesiboListener.prototype.Mesibo_onMessageUpdate = function(m) {
    // You will receive message updates here
}

MesiboListener.prototype.Mesibo_onMessageStatus = function(m) {
    // You will receive the status of sent messages here 
}

Complete code on GitHub for Pythonopen_in_new

class PyMesiboListener(MesiboListener):

    def Mesibo_onConnectionStatus(self, status):
        """A status = mesibo.MESIBO_STATUS_ONLINE means the listener
        successfully connected to the mesibo server
        """
        print("## Mesibo_onConnectionStatus: ", status)
        if(status == mesibo.MESIBO_STATUS_AUTHFAIL):
            exit(1)
        return 0

    def Mesibo_onMessage(self, msg):
        """Invoked on receiving a new message
        or reading database messages
        msg: Message Object
        """
        print("\n ## Mesibo_onMessage: ", msg)
        return 0

    def Mesibo_onMessageUpdate(self, msg):
        """Invoked on receiving a message update
        """
        print("\n ## Mesibo_onMessageUpdate: ", msg)
        return 0

    def Mesibo_onMessageStatus(self, msg):
        """Invoked when the status
        of an outgoing or sent message is changed.
        """
        print("## Mesibo_onMessageStatus", msg)
        return 0

    def Mesibo_onPresence(self, msg):
        print("## Mesibo_onPresence", msg)
        return 0

Complete code on GitHub for C++open_in_new

int Mesibo_onMessage(MesiboMessage *msg) {
    logMessage(msg, "Mesibo_onMessage");
    return 1;
}

int Mesibo_onMessageUpdate(MesiboMessage *msg) {
    logMessage(msg, "Mesibo_onMessageUpdate");
    return 1;
}

int Mesibo_onMessageStatus(MesiboMessage *msg) {
    logMessage(msg, "Mesibo_onMessageStatus");

    return 1;
}

int Mesibo_onConnectionStatus(int status) {
    ERRORLOG("===> Mesibo_onConnectionStatus: %u\n", status);
    return 0;
}

Step 2: Initialize mesibo

Initializing mesibo is a straightforward process. At a minimum, it requires the user access token, the name of the database where mesibo will store all messages and data, and the listener object explained in the previous section.


Complete code on GitHub for Javaopen_in_new

Mesibo api = Mesibo.getInstance();
api.init(getApplicationContext());

// Set the user access token
Mesibo.setAccessToken(token);

Mesibo.addListener(this);

// Set the name of the database
Mesibo.setDatabase("mesibo");

// Start mesibo,
Mesibo.start();

Complete code on GitHub for Kotlinopen_in_new,

val api: Mesibo = Mesibo.getInstance()
api.init(applicationContext)

// Set the user access token
Mesibo.setAccessToken(token)

Mesibo.addListener(this)

// Set the name of the database
Mesibo.setDatabase("mesibo", 0)

// Start mesibo,
Mesibo.start()

Complete code on GitHub for Swiftopen_in_new

// Set the user access token
Mesibo.getInstance().setAccessToken(token)

Mesibo.getInstance().addListener(self)

// Set the name of the database
Mesibo.getInstance().setDatabase("mesibo")

// Start mesibo,
Mesibo.getInstance().start()

Complete code on GitHub for Objective-Copen_in_new

// Set the user access token
[MesiboInstance setAccessToken:token];

[MesiboInstance addListener:self];

// Set the name of the database
[MesiboInstance setDatabase:@"mesibo"];
    
// Start mesibo,
[MesiboInstance start];

Complete code on GitHub for Flutteropen_in_new

Mesibo _mesibo = Mesibo();

// Set the user access token
_mesibo.setAccessToken(token);

_mesibo.setListener(this);

// Set the name of the database
_mesibo.setDatabase("mesibo");

// Start mesibo,
_mesibo.start();

Complete code on GitHub for JavsScriptopen_in_new

var api = new Mesibo();

// Set the user access token
api.setAppName("com.mesibo.firstapp");
api.setAccessToken(token);

api.setListener(listener);

// Set the name of the database
api.setDatabase("mesibo");

// Start mesibo,
api.start();

Complete code on GitHub for Pythonopen_in_new

#!/usr/bin/python3
import mesibo
from mesibo import MesiboListener

# Create a Mesibo Instance
api = mesibo.getInstance()

api.addListener(listener)

# Set the user access token
api.setAppName("com.mesibo.firstapp")

if(mesibo.MESIBO_RESULT_FAIL == api.setAccessToken(ACCESS_TOKEN)):
    print("===> Invalid ACCESS_TOKEN: ", ACCESS_TOKEN)
    print("See https://docs.mesibo.com/tutorials/get-started/")
    exit(1)

# Set the name of the database
api.setDatabase("mesibo", 0)

# Start mesibo,
api.start()

Complete code on GitHub for C++open_in_new

#include <mesibo.h>

Mesibo *m_api = MesiboInstance(0);

// Set the user access token
m_api->setAppName(APP_ID);
m_api->setAccessToken(APP_TOKEN);
	
m_api->addListener(listener);

// setup database to store incoming messages
if(0 != m_api->setDatabase("mesibo.db", 0)) {
	return -1;
}

// start mesibo
m_api->start();

That's it! Your app will now establish a connection and be ready to send and receive messages, make calls, and engage in conferencing, among other functionalities.

mesibo manages the connection and reconnection process whenever your device connects or disconnects from the network, hence you don't need to worry about it. Whenever your app goes online or offline, the Mesibo_OnConnectionStatus function will be triggered. Your app can even send messages while offline, and mesibo will automatically deliver them once a connection is established.

Now we are ready to run the app.

Step 3: Build Application

Now let's configure user access token, build and run the First App you downloaded from GitHubopen_in_new. Follow the instructions for configuring user access token your preferred programming language.


Open your project in Android Studio and configure the user access token and address in the code show below. The sample app supports configuring two tokens so you can test messaging and calls between multiple devices or simulators.

DemoUser mUser1 = new DemoUser("<token 1>", "User-1", "123");
DemoUser mUser2 = new DemoUser("<token 2>", "User-2", "456");

This project already includes the mesibo SDKs. But if you are integrating mesibo into your own app, you can add the mesibo SDKs by following the installation instructions.

After configuring the users, sync Gradle, build the project, and run it to test out messaging and calls. Login with User-1 on one device and User-2 on another.

Open your project in Android Studio and configure the user access token and address in the code show below. The sample app supports configuring two tokens so you can test messaging and calls between multiple devices or simulators.

internal var mUser1 = DemoUser("<token 1>", "User-1", "123")
internal var mUser2 = DemoUser("<token-2>", "User-2", "456")

This project already includes the mesibo SDKs. But if you are integrating mesibo into your own app, you can add the mesibo SDKs by following the installation instructions.

After configuring the users, sync Gradle, build the project, and run it to test out messaging and calls. Login with User-1 on one device and User-2 on another.

Open your project in Xcode and configure the user access token and address in the code show below. The sample app supports configuring two tokens so you can test messaging and calls between multiple devices or simulators.

var mUser1: [String: String] = [
    "name": "User-1", "address": "123", "token": "<token 1>"
];
    
var mUser2: [String: String] = [
    "name": "User 2", "address": "456", "token": "<token-2>"
];

This project already includes the mesibo SDKs. However, you should update frameworks by running command:

$ pod update

If you are integrating mesibo into your own app, you can add the mesibo SDKs by following the installation instructions.

After the pod update, build the project, and run it to test out messaging and calls. Login with User-1 on one device and User-2 on another.

Open your project in Xcode and configure the user access token and address in the code show below. The sample app supports configuring two tokens so you can test messaging and calls between multiple devices or simulators.

mUser1 = @{
    @"token": @"<token 1>", @"name": @"User 1", @"address": @"123"
};
    
mUser2 = @{
    @"token": @"<token 2>", @"name": @"User 2", @"address": @"456"
};

This project already includes the mesibo SDKs. However, you should update frameworks by running command:

$ pod update

If you are integrating mesibo into your own app, you can add the mesibo SDKs by following the installation instructions.

After the pod update, build the project, and run it to test out messaging and calls. Login with User-1 on one device and User-2 on another.

Open your project in Android Studio or Xcode and configure the user access token and address in the code show below. The sample app supports configuring two tokens so you can test messaging and calls between multiple devices or simulators.

DemoUser user1 = DemoUser("user-auth-token-for-user-1", '<user2-address>');
DemoUser user2 = DemoUser("user-auth-token-for-user-2", '<user1-address>');

This project already includes the mesibo SDKs. However, you should update mesibo Flutter SDKopen_in_new by running command:

$ flutter pub upgrade

If you are running it on iOS, download and install mesibo dependencies

$ cd ios 
$ pod install
$ pod update

Build the project, and run it to test out messaging and calls. Login with User-1 on one device and User-2 on another.

Open mesibo-demo.js in your favorite editor and configure the user access token and address in the code show below.

var demo_user_token = '<token>';
/* App ID used to create a user token. */
var demo_appid = 'com.mesibo.firstapp';
/* A destination where this demo app will send message or make calls */
var demo_destination = '18005551234';

Now open demo.html in a browser window. Login to test out messaging and calls.

Open mesibo-demo.py in your favorite editor and configure the user access token and address in the code show below.

ACCESS_TOKEN = "<token>"
APP_ID = "com.mesibo.firstapp"

Install mesibo Python SDK by following the installation instructions.

Now run mesibo-demo.py in a browser window. Login to test out messaging and group messaging.

Open mesibo.cpp in your favorite editor and configure the user access token and address in the code show below.

#define APP_TOKEN "<token>"
#define APP_ID "com.mesibo.firstapp"

Install mesibo C++ SDK by following the installation instructions.

Build executable by:

$ g++ mesibo.cpp -lmesibo -o mesibo_sample

Now run mesibo_sample to test out messaging and group messaging.


Step 4: Run and Test Application

Run the app you built in the previous step. You should install the app on two devices. On the first device, click on the Login as User1 button and on another device, click on the Login as User2 button. If you do not have two devices, you can also use web messengeropen_in_new as second user to try your app.

You need to ensure that your app successfully connects with mesibo server. This you can check by observing connection status.

If you add a breakpoint on Mesibo_onConnectionStatus, you will see that it cycles through various status information. Finally, you should receive status=1 which indicates that your app is successfully connected to the mesibo real-time server and ready to send and receive real-time messages.

Once the connection is successful, you can send messages to each other and can also make voice and video calls.

Do not move forward till the connection is successful

If you are not getting connection status 1, and getting 4 or 5, you are not passing the correct appid while creating a token. Please regenerate the token and try again. Mesibo also prints debug logs in the console which should help further diagnose the issue.

You can contact usopen_in_new if you still having an issue connecting.

Once you receive the connection status 1, you can explore all the demo features.You can also add a breakpoint on Mesibo_onMessage to see that you got the messages there.

In next few sections, we will explain more mesibo features.