Mesibo Presence APIs - Online Status, Typing Indicators and more

Estimated reading time: 5 minutes

Mesibo presence APIs allow your active users to share their activities, for example, online and offline status, typing indicator, joining and leaving the chat, game actions, etc. as it happens in real-time. While sending and receiving presence information is completely optional, it can greatly enhance chat engagement. In mesibo, we refer to the Presence Information as User Activity.

You can define and send different types of custom activities to meet your app requirements. Mesibo also has some pre-defined activities, as described below.

Online and Offline Status

A user can show his or her Online and Offline Status to other users or group members by sending Online and Offline activities. On the receiving end, UI can show online status, typically by showing a green dot or by showing the text Online below the username. However, it is entirely up to your app how to show it.

Note, you generally do not need to send Online and Offline activities as mesibo can automatically send them for you. You only need to configure when to show online status and privacy. We will describe that in detail in the later section.

Typing Indicators

A user can show he or she is typing or has stopped typing to other users or group members by sending Typing Activities. On the receiving end, UI can show typing indicator, typically by showing a showing “typing” or “User is Typing” below the username. However, it is entirely up to your app how to show it.

Join and left Indicators

A user can also show that he or she has joined or left the conversation by sending JOIN or LEFT activity.

Sending an Activity

You can send an Activity by calling sendActivity API. The sendActivity API call is similar to sendMessage API. It will send Activity to another user or a group. On receiving side, Mesibo_onActivity callback function in the listener will be called with the activity.

int MesiboProfile.sendActivity(long mid, long activity);

sendActivity takes the following parameters:

Parameter Description
mid Message-ID for sending messages.
activity Activity

For example,

mProfile.sendActivity(Mesibo.random(), MESIBO_ACTIVITY_TYPING);

Automatically Sending Online and Offline Status

While you can send Online and Offline activities manually as described above, mesibo let you automate the entire task of sending online and offline status depending on your app state. You only need to select the online mode, target, and privacy options.

Online Modes

You can select one of the following modes to decide when your app should show your users Online.

Online when the App Is Active (Default)

Send online status when the user is logged in and actively using the app (the app is in the foreground). Mesibo sends offline when the app moves to the background. This is the default mode and most appropriate for most applications.

Online on Login

Send online status when the user logs in and offline when the user disconnects. In this mode, the user may be shown online even though the user is not actively using the app, for example, the user was logged in while the app is in the background. Hence it is not recommended to use this mode unless your application demands it.

Manual

Mesibo calls a callback function when someone requests the online status. Depending on your application logic, you can send online status or ignore it.

You can select online mode by calling setOnlineMode API.

void setOnlineMode(int mode);

setOnlineMode takes the following parameters:

Parameter Description
mode Online Mode

For example,

setOnlineMode(MESIBO_ONLINEMODE_FOREGROUND);

Target Audience for Online status

By default, the online status is sent to a special group MESIBO_GROUP_PROVSUBSCRIBERS, which results in sending the status to all users who have subscribed to your online status. You can change this to any other special group or any group you have created by calling setOnlineTarget API.

void setOnlineTarget(long groupid);

setOnlineTarget takes the following parameters:

Parameter Description
groupid Group ID. It can be a special group ID or any other group that you have created

For example,

setOnlineGroup(MESIBO_SPECIALGROUP_PROVSUBSCRIVERS);
}

Refer to the group API documentation to learn about the special group.

Online status Privacy

By default, the online status is sent to anyone who has requested it. You can change the privacy to contacts only by calling setOnlinePrivacy API. Another way to change privacy is to select the target which sends to contacts only.

void setOnlinePrivacy(int privacy);

setOnlineTarget takes the following parameters:

Parameter Description
privacy Privacy mode

For example,

setOnlinePrivacy(MESIBO_ONLINESTATUS_PUBLIC);
presence, SIP, online status, offline status, typing indicators