Group Messages

Update time: 2023/03/24 11:10:29

NIM SDK can send and receive messages in groups, receive notification messages for group operations, and set message notification modes.

Messaging in groups

You can send and receive multiple types of messages in group chats.

After creating or joining a group, the interface used to send and receive messages is the same as that of P2P messaging. The difference lies in the of the session type (NIMSessionType). Select kNIMSessionTypeTeam for group messages.


Enumeration Description
kNIMSessionTypeP2P One-on-one chat
kNIMSessionTypeTeam Advanced group
kNIMSessionTypeSuperTeam Supergroup

For information about how messaging works, see Messaging.

Group notification messages

NIM SDK provides built-in message types (NIMMessageType). Notifications (`kNIMMessageTypeNotification·) are sent for events of groups, chat rooms and supergroups. Notifications of this type are sent by the CommsEase server, and clients cannot send notification messages.

The following events trigger group notification messages.

NIMNotificationId Description
kNIMNotificationIdTeamSyncCreate A group is created.
kNIMNotificationIdTeamInviteAccept An invitation is accepted with consent.
kNIMNotificationIdTeamInvite An invitation is accepted without consent.
kNIMNotificationIdTeamMemberChanged Group members change.
kNIMNotificationIdTeamAddManager A new administrator is added.
kNIMNotificationIdTeamKick A member is removed.
kNIMNotificationIdTeamOwnerTransfer The ownership is transferred.
kNIMNotificationIdTeamApplyPass A join request is approved.
kNIMNotificationIdTeamRemoveManager An administrator is removed.
kNIMNotificationIdTeamDismiss A group is deleted.
kNIMNotificationIdTeamLeave A member leaves a group.
kNIMNotificationIdTeamMuteMember A member is muted or unmuted.
kNIMNotificationIdTeamUpdate The group profile is updated
kNIMNotificationIdTeamSyncUpdateMemberProperty The member profile is updated.
kNIMNotificationIdLocalGetTeamMsgUnreadCount Get unread count of group messages.
kNIMNotificationIdLocalGetTeamMsgUnreadList Get the list of unread group messages.


The SDK can set the configuration of the alert mode for message notifications. Group message alerts are divided into:

  • All messages are alerted (default)
  • Only messages sent from the group owner and administrators are alerted
  • No alert

The alerts belong to Push service and alerts provided by the CommsEase SDK.

The alert mode of messages does not affect receiving messages and the unread count. If you set the alert mode to no alerts, you can still receive group messages, and the unread count will still change.

Set the Do-Not-Disturb status


Set the option to alert group messages by calling the UpdateMyPropertyAsync method.

**Interface prototype: **

static bool nim::Team::UpdateMyPropertyAsync	(const TeamMemberProperty & 	prop,
                                                 const TeamEventCallback & 	cb,
                                                 const std::string & 	json_extension = "" 


Parameter Description
prop Member attribute. For more information, see TeamMemberProperty
json_extension Custom extension field
cb Callback for edit the member profile.

Sample code:

long long new_bits = 0;
if (All messages are alerted)
	new_bits &= ~nim::kNIMTeamBitsConfigMaskMuteNotify;
else if (No alert)
	new_bits |= nim::kNIMTeamBitsConfigMaskMuteNotify;
else//Only messages sent from administrators are alerted.
	new_bits |= nim::kNIMTeamBitsConfigMaskOnlyAdmin;
nim::TeamMemberProperty values(Group ID, account ID, and role);
nim::Team::UpdateMyPropertyAsync(values, nbase::Bind(&TeamCallback::OnTeamEventCallback, std::placeholders::_1));

void TeamCallback::OnTeamEventCallback(const nim::TeamEvent& result)

Error codes

Code Description
200 The operation was successful.
803 Group does not exist
804 The user is not a member of a group.
805 Invalid group type

Set the option to alert group messages by calling the nim_team_update_my_property_async function.

Sample code:

static CallbackFunc(int res_code,
    int notification_id,
    const char* tid,
    const char* result,
    const char* json_extension,
    const void* user_data){
	printf("res_code %d", res_code);

// const char* team_info_json = ......
nim_team_update_my_property_async(team_info_json, "", &CallbackFunc, NULL);

Query Do-Not-Disturb


Get the alert type for group notifications by calling the GetBits method in TeamMemberProperty.

Sample code

TeamMemberProperty prop{};
// ...
int64_t bits = prop.GetBits();
if ( bits & kNIMTeamBitsConfigMaskMuteNotify ) {
	std::cout << "Close alert";
} elseif ( bits & kNIMTeamBitsConfigMaskOnlyAdmin ) {
	std::cout << "Receive only messages sent by administrators";

Get the alert type for group notifications with the bits in NIMTeamMemberInfo.

Sample code

// team_member_prop_json
int64_t bits = team_member_prop_json[nim::kNIMTeamUserKeyBits].asInt64();
if ( bits & kNIMTeamBitsConfigMaskMuteNotify ) {
  printf("Close alerts");
} elseif ( bits & kNIMTeamBitsConfigMaskOnlyAdmin ) {
  printf("Receive only messages sent by administrators");

Read receipt for group messages

For read receipt for group messages or queries of unread count of group messages , see Read receipt of group messages.

API reference

UpdateMyPropertyAsync Set the option to alert group messages
GetBits Get the alert type for notification messages
TeamMsgAckReadEx Read receipt of group messages.
TeamMsgQueryUnreadList Get the list of members that have not read a specified message.
TeamMsgQueryUnreadList Get the list of members that have read or unread group messages by group ID.
nim_team_update_my_property_async Set the option to alert group messages
nim_team_msg_ack_read_ex Read receipt of group messages.
nim_team_msg_query_unread_list Get the list of members that have not read a specified message.
Was this page helpful?
  • Messaging in groups
  • Group notification messages
  • Do-Not-Disturb
  • Set the Do-Not-Disturb status
  • Query Do-Not-Disturb
  • Read receipt for group messages
  • API reference