Implement group announcements and status information

更新时间:
复制 MD 格式

The Interactive Message Service SDK lets you easily implement business requirements, such as group announcements and status information, without requiring additional support from your business servers.

Procedure

  1. Information about custom audience groups.

  2. When a client successfully joins a group, it receives the group details through the onSuccess callback function. The ImJoinGroupRsp response contains the group information.

    ImJoinGroupReq req = new ImJoinGroupReq();
    req.groupId = groupId;
    groupInterface.joinGroup(req, new ImSdkValueCallback<ImJoinGroupRsp>() {
        @Override
        public void onSuccess(ImJoinGroupRsp data) {
            
        }
    
        @Override
        public void onFailure(Error error) {
    	}
    });
  3. When group information changes, clients receive real-time update notifications through the onInfoChange group listener. If you set this listener, all relevant clients are immediately notified of the change through a callback.

    // Add a group listener
    groupManager.addGroupListener(new ImGroupListener() {
        @Override
        public void onMemberChange(String groupId, int memberCount, ArrayList<ImUser> joinUsers, ArrayList<ImUser> leaveUsers) {
            
        }
        @Override
        public void onExit(String groupId, int reason) {
        }
        @Override
        public void onMuteChange(String groupId, ImGroupMuteStatus status) {
        }
        @Override
        public void onInfoChange(String groupId, ImGroupInfoStatus info) {
        }
    });

    The ImGroupInfoStatus object in the onInfoChange callback contains the group information.

What to do next

  • The flexible definition of group information supports various business needs. For example, you can define the group information as a JSON string in the following format:

    {
       "GroupStatus": 1, // "Not started"
       "Message":"Live from 7 PM to 9 PM every night",
       ...
       "notice":"Be respectful"
    }
  • When a user joins the group or the group information changes, the client receives the updated group information in real time.