Get Started: Group Messaging

Estimated reading time: 8 minutes

In this part, we will learn about group messaging.

Prerequisites

You MUST go through the following prerequisites before you read further.

  • Read the First App Guide.
  • Read one of the Android, iOS, JS section of this tutorial.

Overview

Understanding Group Management APIs

mesibo allows you to create groups having a set of users as group members. Once you create a group, you can send messages to the group, and all the group members will receive the messages. You can create groups of any size without any restrictions.

To use group messaging, you only need to perform the following:

  • Create a group

  • Add members

  • Start sending messages

There are various kinds of group messaging possible with mesibo, to categorize a few:

  • Normal group: any group member can send and receive messages to a group.

  • Restricted group: only selected group members can send messages to a group and selected group members can receive messages from the group. Senders and receivers can be a disjoint set.

  • Broadcast group: only the admin can send messages to the group.

  • Public Rooms: anyone can message, even non-members.

  • Round-robin (hunt): only one group member from the group will receive the message in round-robin fashion. This is quite useful for creating specialized groups; for example, in a group of support staff, only one of them will receive a message from a customer.

However, instead of hardcoding group types, mesibo allows you to specify the sending and receiving behavior of the group and individual group members for greater flexibility, for example,

  • Anyone can send
  • Members can send
  • Only selected members can send
  • Only Selected Members can receive
  • Members can receive
  • One of the active members can receive, etc

You can dynamically change the group or the member behavior at any point in time and it will be instantly applied to the group or group member(s).

Creating a Group

You can create a group either using Mesibo Backend APIs(recommended) or in the console. To develop a real app, you may need to dynamically create groups and modify them, for which you can only use REST-based backend APIs. Here, we will describe both the methods for creating a group - using REST APIs as well as using the console.

Creating a group using REST API

You need to use Group Management REST APIs.

To create a group, invoke the backend API with the following parameters:

  • op = “groupadd”
  • token = Application Token obtained from mesibo console
  • name = Group Name [Optional]
  • flag = Group Flags (described below)
  • expiry = Expiry in seconds, default 1 year
  • expiryext = Auto extend expiry on group activity, in seconds. Default disabled.
  • active = 1 to enable, 0 to disable Group Flags can be a logical OR combination of one or more flags value below:

  • 0 - normal group, only members can send
  • 1 - only selected members can send (refer add members API below)
  • 2 - anyone can send
  • 0x10 - only selected members can receive (refer add members API below)
  • 0x20 - received by one member in the round-robin fashion
  • 0x40 - do no store group messages
  • 0x80 - loop back to the sender

Response Fields

response[‘group’][‘gid’] = Group ID (GID)

Example:

https://api.mesibo.com/api.php?op=groupadd&token=123434343xxxxxxxxx&name=testGroup&flag=0

If you have hosted the mesibo backend at https://example.com/api.php use that as the REST endpoint.

https://example.com/api.php?op=groupadd&token=123434343xxxxxxxxx&name=testGroup&flag=0

If group creation is successful, you should receive a response that looks like below

{..<truncated>.. ,"group":{"gid":102529},"op":"groupadd","result":true}

In the above example, we have created a group with the group-id 102529. Make note of this. You can save this group-id and other group information in your database so that you can access it later. To perform any kind of group management operations like adding or deleting members, changing group permissions, etc. you will need a valid group-id.

Add Group Members using REST API

Now you can add Group Members using GID obtained in that you obtained when you created the group.

  • op = “groupeditmembers”
  • token = Application Token obtained from mesibo console
  • gid = Group ID (GID)
  • m = comma-separated list of user addresses to add or remove in the group
  • cs = 1 if members being added can send messages to the group, 0 for not
  • cr = 1 if members being added can receive group messages, 0 for not
  • canpub = [group calling] 1 if members being added can make (publish) group voice or video calls, 0 for not
  • cansub = [group calling] 1 if members being added can subscribe to group voice or video calls, 0 for not
  • canlist = [group calling] 1 if members being added can get a list of active callers in the group, 0 for not
  • delete = 0 to add members, 1 to remove members

You can only add valid users to the group. So, before you proceed ensure you have created users

For example, to add members with address member1, member2, member3 to the group with group-id 102529 invoke the API as follows:

https://api.mesibo.com/api.php?op=groupeditmembers&token=123434343xxxxxxxxx&gid=102529&m=member1,member2,member3&delete=0

Now, we will learn how to create a group and manage it from the mesibo console.

Creating a Group in mesibo console

To create a new group, click on the + NEW GROUP button. Give a group name - example Mesibo Group and click onCreate. Your group with the name ConferenceGroup should now be created and be displayed in the table. Click on the edit icon, under actions. This will open the Group Settings page. Replicate settings shown below.

Group Permissions

Adding users to your Group in mesibo console

Click on the + NEW MEMBER button and enter the user address whom you wish to add. Click on Add. The Members table will now display the member you just added. Similarly, add more users.

The users you add should be existing mesibo users. Otherwise, create those users before you try to add them.

Group Members

How to Send Group messages

To send a group message, you need to invoke one of the messaging APIs. You can specify the destination as the groupid. mesibo will send the message to the group and also inform you about the status of messages sent in real-time.

For example, here is an example of how you use sendMessage to send a message to a group. Let’s say you have created a group with the group-id 96568. Then you use the same function that you use for sending one to one message, where instead of setting the peer to the user address, now you set it to the group -id.

Example,

Using Java,

Mesibo.MessageParams p = new Mesibo.MessageParams();
p.groupid = 96568;
p.flag = Mesibo.FLAG_READRECEIPT | Mesibo.FLAG_DELIVERYRECEIPT;
String message = "This is a group message";		
Mesibo.sendMessage(p, Mesibo.random(), message);

Using Kotlin,

p.peer = mRemoteUser!!.address
p.flag = Mesibo.FLAG_READRECEIPT or Mesibo.FLAG_DELIVERYRECEIPT
private val message = "This is a group message"
Mesibo.sendMessage(p, Mesibo.random(), message)

Using Objective-C,

MesiboParams *params = [MesiboParams new];
params.groupid = 96568;
params.flag = MESIBO_FLAG_READRECEIPT | MESIBO_FLAG_DELIVERYRECEIPT;
uint32_t mid = [MesiboInstance random];
NSString *message = @"This is a group message";
[MesiboInstance sendMessage:params msgid:id string:message];

Using Swift,

let params = MesiboParams()
params.peer = mRemoteUser
params.flag = (UInt32)(MESIBO_FLAG_READRECEIPT | MESIBO_FLAG_DELIVERYRECEIPT)
let mid = Mesibo.getInstance()!.random()
let message = "This is a group message"
Mesibo.getInstance()!.sendMessage(params, msgid: mid, string: message)

Using Javascript,

var p = {};
p.groupid = 96568;
var id = parseInt(Math.random()*10000);
var string = "This is a group message";
api.sendMessage(p, id, message);	

A message sent will be delivered to all members of the group and you will get the message delivery status for each user.

Reading Messages >>

mesibo, android, ios, js