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:
- Download the source code of the app in this tutorial from the mesibo GitHub repositories.
- Open it in your IDE (Android Studio, Xcode etc). Follow along as you go through this tutorial.
Step 1: Set Up mesibo Listeners
mesibo is a real-time, asynchronous platform. Messages, calls, and status updates can arrive at any moment — your app does not poll or check for them. Instead, you register listeners that mesibo calls instantly the moment an event occurs.
This means you write your logic once, wire it up to the appropriate listener, and mesibo handles the rest — whether your app is in the foreground, processing other work, or sitting idle in background.
mesibo will invoke your listeners for events such as:
- Incoming message →
Mesibo_OnMessage - Message sent, delivered, or read →
Mesibo_OnMessageStatus - Incoming call →
MesiboCall_OnIncoming - Connection status change (online/offline) →
Mesibo_OnConnectionStatus - And more…
To set up listeners, create a class that implements the mesibo listener interfaces and register it with mesibo before starting the service. Examples for each supported platform are shown below — refer to the app source code for the complete implementation.
Complete code on GitHub for Java
@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 Kotlin,
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 Swift
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-C
-(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 Flutter
@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 JavsScript
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 Python
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++
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;
}
Here’s the refined version:
Step 2: Initialize mesibo
Initialization is minimal by design. To get mesibo running, you only need three things:
- A user access token for the current user, which we created in previous section
- A database name where mesibo will persist messages and data locally
- The listener object you set up in the previous step
Complete code on GitHub for Java
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 Kotlin,
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 Swift
// 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-C
// 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 Flutter
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 JavsScript
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 Python
#!/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++
#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 all it takes. mesibo will establish a connection and your app is immediately ready to send and receive messages, make calls, and join conferences.
From this point on, mesibo fully manages the connection lifecycle — including automatic reconnection whenever your device loses and regains network access. You never need to write reconnection logic or monitor network state yourself. Whenever the connection status changes, mesibo will notify you via Mesibo_OnConnectionStatus.
One more thing worth noting: your app can send messages even while offline. mesibo queues them locally and delivers them automatically once connectivity is restored — no extra handling required on your part.
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 GitHub. 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 SDK 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 Your Application
Install the app on two devices. On the first device, tap Login as User1 and on the second, tap Login as User2. If you only have one device, you can use the mesibo Web Messenger as the second user.
Verify the Connection
Before testing messaging or calls, confirm that your app is successfully connecting to mesibo. Add a breakpoint on Mesibo_OnConnectionStatus and observe the status codes as mesibo cycles through the connection sequence. You are looking for:
status = 1— Connected. Your app is online and ready to send and receive messages in real time.status = 4orstatus = 5— Authentication failure. This typically means theappidused when generating the user access token does not match. Regenerate the token with the correctappidand try again.
Do not proceed to the next step until you receive
status = 1. Everything that follows depends on a successful connection. You can contact us if you still having an issue connecting.
mesibo also prints diagnostic logs to the console — check those if the connection status is not what you expect.
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.