Write your First mesibo Enabled Application

Excited to see real-time messaging in action? We are too..

First Step

Before we start coding our first Android, iOS or web application - we need to perform a few steps that are common across platforms. You can perform these steps using mesibo server-side API or mesibo console.

Let’s say you are creating a new app ‘BingoMessage’ for Android, iOS and web.

  1. Add a new Application ‘BingoMessage’ using mesibo console (or using mesibo server-side API).
  2. Create users for this application using console or server-side api. You may use console to create a small number of users; however this job is best handled by using server-side API. An access token is generated for each user that will be passed to client-side API to create real-time connection.
  3. [Optional] Create groups, using console or server-side api.
  4. That’s it - now users can start communicating with each other in real-time using mesibo’s real-time client side API for Android, ios or web.

Isn’t it simple? So let’s quickly move to create our first application.

Make Note of your API Key & Application Token

You can view your API key and Application token in the console. Note this as you will need it in next steps.
In this example,

API Key: k6ci4gmdbwfnxf0j9ai8e3o2zj7cxusiebamn7oqcyfr3yx9ng13pn3ihqdnyn54

mesibo-api-key

Create Your Application

Create an Application that will hold all your users and groups. You can create an Application (Apps->New App) from the console OR you can use API key and invoking server-side API, for example,

New Application Request

https://mesibo.com/api/api.php?key=k6ci4gmdbwfnxf0j9ai8e3o2zj7cxusiebamn7oqcyfr3yx9ng13pn3ihqdnyn54&op=appadd&
name=BingoMessage

The above API returns JSON response like this,

Response

{"account":{"uid":"10","oid":"9","msgs":"0","users":"0","groups":"0","conns":"0","apps":"0","storage":"0","pid":"1","billday":"1",
"status":"0","flag":"0","expiry":"2020-09-01
22:38:45","issuetime":"2017-09-01
22:38:45"},"plan":{"name":"Starter","msgs":"100000","users":"10000","groups":"10000","conns":"25","apps":"5","storage":"1",
"amount":"0.0000"},"app":{"name":"BingoMessage","token":"jin696y9gipbk9of7cjipgu06chg9lncbazmaletsj98exrp972dvols80
pnhzqi
"},"op":"appadd","result":true}

As you can see from the response that the application has been successfully created and the application token is

jin696y9gipbk9of7cjipgu06chg9lncbazmaletsj98exrp972dvols80pnhzqi

We can use this application token to create users and groups for this application.

hand-pointing-to-right-direction You can also create an application from the console by clicking on ‘New Application’ button from the dashboard.

Create Users (Endpoints)

Once you have created your Application, it’s time to add users and groups. Typically, you will add users and groups dynamically on need basis. However, for this sample app, you can create a few users and groups manually so that you can test messaging between them.

Let’s say we are creating a user 18005550001 which should be used on Android or iOS app having app id (bundle id in iOS) - com.mesibo.demoapp. We will be using app token obtained in the previous step.

User Creation Request

https://mesibo.com/api/api.php?token=jin696y9gipbk9of7cjipgu06chg9lncbazmaletsj98exrp972dvols80pnhzqi&op=useradd&
appid=com.mesibo.demoapp&addr=18005550001

Where
appid = Android or iOS app id (for example, com.mesibo.xxx). In case of web, just pass, ‘web’ as appid. Note that, for security reasons, the token generated for a particular appid will only be usable on app matching that appid.
addr = end point address, for example, a user phone number.

You can find more about server-side API in the reference section. The above API returns JSON response like this,

Response

{"account":{"uid":"10","oid":"9","msgs":"0","users":"0","groups":"0","conns":"0","apps":"0","storage":"0","pid":"1","billday":"1","status":
"0","flag":"0","expiry":"2020-09-01
22:38:45","issuetime":"2017-09-01
22:38:45"},"plan":{"name":"Starter","msgs":"100000","users":"10000","groups":"10000","conns":"25","apps":"5","storage":"1","amount":"0.0000"}
,"app":{"name":"BingoMessage","token":"jin696y9gipbk9of7cjipgu06chg9lncbazmaletsj98exrp972dvols80pnhzqi"},"op":"appadd","
result":true}

The above API returns JSON response with access token, that will be used by Android, iOS and web application to connect to mesibo real-time server (using setAccessToken API).

You can now create more users in similar fashion so that you test messaging between them. You can also send messages to a particular user from console from ‘Users’ section.

hand-pointing-to-right-direction You can also create users from the console by clicking on ‘New User’ button from the Application settings page.

We are now all set to create our first mobile app.

Which mobile app platform would you like to get started with?

Create a Basic Application

Once we created an Application and Users as described in the previous section, we are now ready to write code for a basic application which can send and receive real-time messages.

Follow these steps to create a new project from scratch. If you already have an application, you can skip those steps. You can also download the sample app project from GitHub

X

We are uploading soon...Meanwhile contact us at- support@mesibo.com

Android

  1. Start Android Studio.
  2. Create a new project with minimum SDK version 9 or higher (14 recommended).
  3. Android Studio starts Gradle and builds your project. This may take a few seconds. For more information about creating a project in Android Studio, see the Android Studio documentation. https://developer.android.com/training/basics/firstapp/creating-project.html
  4. Add mesibo SDK to your project by adding gradle dependency and performing gradle sync as explained in installation instructions.
  5. Add mesibo initialization code in your onCreate method
  6. 								import com.mesibo.api.mesibo;
    								…

    
    						@Override
    						protected void onCreate(Bundle savedInstanceState) {
    							super.onCreate(savedInstanceState);
    							setContentView(R.layout.activity_main);
    
    							mesibo api = mesibo.getInstance();
    							api.init(this);
    
    							api.addListener(this);
    
    							// set user authentication token obtained by creating user
    							api.setAccessToken("3c1c4711f7617c56b151553b7e63bde5da7bbe119e");
    							api.start();
    						}
    					

  7. Extend your activity to Implement mesibo.MessageListener and mesibo.ConnectionListner class
  8. 				public class MainActivity extends AppCompatActivity implements mesibo.MessageListener {

    Easiest way is to click on the menu, Code->Implement Methods and it will automatically generates the code for all the methods.

  9. That’s it - you are now ready to receive your first real-time message

iOS

  1. Start xCode.
  2. Create a new project.
  3. Add mesibo SDK to your project now by adding gradle dependency and perform gradle sync as explained in installation instructions.
  4. Drag mesibo.framework to your xcode project. xCode will prompt you for various options - make sure to select "Copy items if needed."
  5. #import < mesibo/mesibo.h > in your project
  6. Add mesibo initialization code in your onCreate method

Testing your first application

  1. Most simple way to test your code is to go to Console ->Application->Users. Select user, type from and message and click on ‘Send Message’.
  2. You can also use two instance of app with different auth token and use mesibo.sendMessage function to send messages between both of them.

Download sample application from GitHub

Use mesibo User Interface (UI) Components

mesibo UI components let you add beautiful messaging user interface in no-time.

  1. Initialize mesibo and set auth token as we did in the Basic Application
  2. Launch UI module by calling
    					mesiboUI.launch(context, 0, false, true);
  3. If you plan to use location feature, add google map API key in the manifest
    					
    					
  4. That’s it.

hand-pointing-to-right-direction Refer to sample app code sample for ready-to-run examples.

How to add file handling

Sending files is not much different than sending plain messages. All you need to do is to first upload the file to a server and then send the URL and thumbnail [optional] using mesibo in real-time. The receiver then downloads it using that URL.

mesibo offers you the flexibility to store all files on your own servers, including private servers or cloud services like Amazon Web Services, Google Cloud Storage, Microsoft Azure etc.

mesibo provides a convenient utility function sendFile, which does most of the job and allows you send various other information along with the file such as title, message, geolocation, etc. Receiver is notified of incoming file in listener function mesibo_onFile()

Note that, you must implement upload and download handler functions in mesiboFileTransferHandler in order to enable sending and receiving files. For more information, refer to FileTransferHandle reference document.

hand-pointing-to-right-direction Refer to FileTransferHandler.java (Android) or FileTransfer.m (iOS) to learn how to create a file handler.