Tutorials

Configuring Group Chats on your Android App using Applozic

Use Applozic’s state-of-the-art chat SDKs to satisfy all your messaging needs
Google+ Pinterest LinkedIn Tumblr

Thanks to advancements in instant messaging, group chats provide a fixed space for groups of any type to talk, share information, and even collaborate in the workplace. However, to avoid the inefficiency and noise sometimes associated with group communication, it may be wise to rely on messaging API platforms that are dedicated to group chat — such as Applozic

In this tutorial, we’ll go over the implementation of various chat group activities, such as creating a group, specifying user roles, and group management.

Prerequisites 

  1. Android Studio (latest version recommended)
  2. Android Device/Emulator with Android v6.0+
  3. Sign-Up or log in to your Applozic Dashboard to get your API/Application Key

Group Types

Applozic supports multiple group types that serve various purposes. Possible values of group type for Create Group API are:

ValueNameDescription
1Private GroupPrivate groups are not accessible to contacts other than the ones present in the group. Only group admins can add/remove members in the group. 
2Public GroupUsers will be able to search and join Public groups. Any group member can add/remove members in this group. 
5Broadcast GroupA message can be sent to several contacts at once. Messages sent in the broadcast group are received by the members of the group as a one-to-one chat thread. 
6Open GroupUsed for free-flowing chats such as live streaming chats, live event chats, etc. 
7GroupOfTwoUsed for the purpose where dealers are selling products and any particular user wants to chat about multiple products with the same dealer. 
9Contacts GroupUsed for creating Friends/Favorites contact List. These lists can be maintained on the application level and any member of the group can access them. 
10Support GroupThese groups are specifically built for the purpose of customer support chat and may contain multiple team members and chatbots talking to a user.

If you’re using Applozic’s default UI for creating a group, you can set the default group type in applozic-settings.json file under the property “defaultGroupType”.

Note: If you have doubts about choosing which group type works the best for you, opt for public groups as they work well for most use-cases.

Create a Group

You can create a group with a specific group type as shown below:

  • Private group with type : Channel.GroupType.PRIVATE.getValue().intValue()
  • Public group with type : Channel.GroupType.PUBLIC.getValue().intValue()
  • Open group with type : Channel.GroupType.OPEN.getValue().intValue()

In the following sections, channelKey refers to the unique identifier of the group/channel, and userId refers to the unique identifier of the user.

Specifying User Roles in a Group

While adding the users to a group, you can specify the roles for them. Group roles are basically of 3 types:

  1. ADMIN (1) – Full access to the group.
  2. MODERATOR(2) – Can add/remove users, update group info.
  3. NORMAL USER(3) – Can update group information

To add members to the group while specifying their role, first create the following task:

AlChannelCreateAsyncTask.TaskListenerInterface channelCreateTaskListener = new AlChannelCreateAsyncTask.TaskListenerInterface() {
            @Override
            public void onSuccess(Channel channel, Context context) {
                Log.i("Group","Group response :"+channel);

            }

            @Override
            public void onFailure(ChannelFeedApiResponse channelFeedApiResponse, Context context) {

            }
        };

ChannelInfo channelInfo = new ChannelInfo("Group name",groupMembersUserIdList);
channelInfo.setType(Channel.GroupType.PUBLIC.getValue().intValue()); //group type
channelInfo.setImageUrl(""); //pass group image link URL

List<ChannelInfo.GroupUser> users = new ArrayList<>();
//SETTING ROLE AS 1 FOR ADMIN
users.add(channelInfo.new GroupUser().setUserId(<userId>).setGroupRole(1));
//SETTING ROLE AS 2 FOR MODERATOR
users.add(channelInfo.new GroupUser().setUserId(<userId>).setGroupRole(2));
//SETTING ROLE AS 3 FOR USER
users.add(channelInfo.new GroupUser().setUserId(<userId>).setGroupRole(3));

channelInfo.setUsers(users);

AlChannelCreateAsyncTask channelCreateAsyncTask = new AlChannelCreateAsyncTask(context,channelInfo,channelCreateTaskListener);

AlTask.execute(channelCreateAsyncTask); //execute task

Add Members to Group

Follow the following steps to configure the addition of members to a group:

  • Make the following import:
import com.applozic.mobicomkit.uiwidgets.async.ApplozicChannelAddMemberTask;
  • Create and execute the task:
ApplozicChannelAddMemberTask.ChannelAddMemberListener channelAddMemberListener =  new ApplozicChannelAddMemberTask.ChannelAddMemberListener() {
            @Override
            public void onSuccess(String response, Context context) {
                //Response will be "success" if user is added successfully
                Log.i("ApplozicChannelMember","Add Response:" + response);
            }

            @Override
            public void onFailure(String response, Exception e, Context context) {

            }
        };

        ApplozicChannelAddMemberTask applozicChannelAddMemberTask =  new ApplozicChannelAddMemberTask(context,channelKey,userId,channelAddMemberListener);//pass channel key and userId whom you want to add to channel

AlTask.execute(applozicChannelAddMemberTask);  //execute task

Remove Members from Group

Follow the following steps to configure the removal of members from a group:

  • Make the following import:
import com.applozic.mobicomkit.uiwidgets.async.ApplozicChannelRemoveMemberTask;
  • Create and execute the task:
ApplozicChannelRemoveMemberTask.ChannelRemoveMemberListener channelRemoveMemberListener = new ApplozicChannelRemoveMemberTask.ChannelRemoveMemberListener() {
            @Override
            public void onSuccess(String response, Context context) {
                //Response will be "success" if user is removed successfully
                Log.i("ApplozicChannel","remove member response:"+response);
            }

            @Override
            public void onFailure(String response, Exception e, Context context) {

            }
        };

  ApplozicChannelRemoveMemberTask applozicChannelRemoveMemberTask =  new ApplozicChannelRemoveMemberTask(context,channelKey,userId,channelRemoveMemberListener);//pass channelKey and userId whom you want to remove from channel

AlTask.execute(applozicChannelRemoveMemberTask); //execute task

Note: Only the admin can remove members from the group/channel.

Change Group Name

  • Make the following import:
import com.applozic.mobicomkit.uiwidgets.async.ApplozicChannelNameUpdateTask;
  • You can change the group name by creating a task as shown below:
You can change the group name by creating a task as shown below:
ApplozicChannelNameUpdateTask.ChannelNameUpdateListener channelNameUpdateListener = new ApplozicChannelNameUpdateTask.ChannelNameUpdateListener() {
            @Override
            public void onSuccess(String response, Context context) {
                //Response will be "success" if Channel/Group name is changed successfully
                Log.i("ApplozicChannel", "Name update:" + response);
            }
            @Override
            public void onFailure(String response, Exception e, Context context) {

            }
        };

  ApplozicChannelNameUpdateTask channelNameUpdateTask = new ApplozicChannelNameUpdateTask(context, channelKey, channelName, channelNameUpdateListener);//pass context ,channelKey,chnanel new name

AlTask.execute(channelNameUpdateTask); //execute task

Mute/Un-mute Group Notifications

Logged-in users can mute a group. You need to pass in the timestamp in UTC till you need to stop notifications from a particular group.

Create a MuteNotificationAsync task as shown below:

final MuteNotificationAsync.TaskListener taskListener = new MuteNotificationAsync.TaskListener() {
            @Override
            public void onSuccess(ApiResponse apiResponse) {
              //Muted successfull
            }

            @Override
            public void onFailure(ApiResponse apiResponse, Exception exception) {
               //Mute Failed
            }

            @Override
            public void onCompletion() {

            }
        };

//millisecond is the future timeStamp in UTC till you want to mute channel.
MuteNotificationRequest muteNotificationRequest = new MuteNotificationRequest(channel.getKey(), millisecond);
MuteNotificationAsync muteNotificationAsync = new MuteNotificationAsync(getContext(), taskListener, muteNotificationRequest);

AlTask.execute(muteNotificationAsync);  //execute task

To un-mute notifications, pass the current timestamp in UTC in the above task.

Conclusion

In this tutorial, we delved into the implementation of group messaging features such as the creation of a group, assignment of user roles, addition/removal of group members, notification management, and various other settings using Applozic’s versatile SDK.

To add more rich messaging features like the listing of group members and categorization of groups, visit Applozic’s documentation website.

Please leave your feedback and doubts in the comments below!

Author

Akash is a Developer Evangelist and an amateur programmer who loves to demystify technology, one article at a time.