Manage messages

Update time: 2024/03/07 11:13:40

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 parameter of the session type (sessionType). Select team for group messages.


Enumeration Description
p2p P2P chat
team Advanced group
superTeam Supergroup
chatRoom Chat room
system System notification

For information about how messaging works, see Messaging.

Notification messages

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

The following events trigger group notification messages.

NIMTeamNotificationTypes Attachment class Description
acceptInvite NIMMemberChangeAttachment A member joins the group after accepting the invitation.
inviteMember NIMMemberChangeAttachment A member are invited to join a group
addTeamManager NIMMemberChangeAttachment An administrator is added
kickMember NIMMemberChangeAttachment A member is removed from a group
transferOwner NIMMemberChangeAttachment The ownership of a group is transferred.
passTeamApply NIMMemberChangeAttachment Join request is accepted
removeTeamManager NIMMemberChangeAttachment An administrator is removed
dismissTeam NIMDismissAttachment A group is dismissed
leaveTeam NIMLeaveTeamAttachment A member leave a group.
muteTeamMember NIMMuteMemberAttachment A member is muted or unmuted.
updateTeam NIMUpdateTeamAttachment The group information is updated.

Parse notification messages:

  1. Get the message type by calling the NIMMessage.messageType method. The notification type indicates a notification message.
  2. Convert the attachment type obtained by [NIMMessage.messageAttachment]( to NIMTeamNotificationAttachment`.
  3. Get the specific notification type (NotificationType) using NotificationAttachment.getType.
  4. Convert the attachment type obtained by NIMMessage.messageAttachment to a corresponding type based on TeamNotificationTypes. See the previous table.
  • For NIMMemberChangeAttachment, get the target of an event using the targets method. For example, if User B is removed from the group, the account of User B can be obtained using the getTargets method.
  • NIMMuteMemberAttachment is the subclass of NIMMemberChangeAttachment. You can get the targets of the event using the targets method and whether the targets are muted or unmuted using mute.
  • For NIMUpdateTeamAttachment, notifications must be parsed for which group profile is updated. Muting groups belongs to this type.

Sample code:

    NimCore.instance.messageService.onMessage.listen((event) {
      print('Test_Observer onMessage ${event.toString()}');
      for (NIMMessage m in event) {
        if(message.messageType = NIMMessageType.notification){
         if (type >= NIMTeamNotificationTypes.inviteMember &&
            type <= NIMTeamNotificationTypes.muteTeamMember) {
               /// See the events that trigger group notifications.


The SDK can set the configuration of the alert mode for message notifications. the alert mode for notifications (NIMTeamMessageNotifyTypeEnum):

  • all: All notifications are alerted (default).
  • manager: Only notifications sent by the group owner and administrators are alerted.
  • mute: all notifications are not alerted.

The alerts belong to [Push service and alerts] ( in the CommsEase system.

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 mute type of a specified group.using muteTeam.


Parameter Description
teamId group ID
notifyType Notification type enumeration
all: All members are alerted.
manager: Only the group owner and administrators are alerted
mute: no alerts

Sample code:

var result = await NimCore.instance.teamService.muteTeam(


Get the alert mode for notifications of a group using NIMTeam.messageNotifyType

Read receipt for group messages

API reference

muteTeam Set the mute type for a specified group.
fetchTeamMessageReceiptDetail Query the specified accounts that have read and unread a message in a group.
queryTeamMessageReceiptDetail Get the specified accounts that have read or unread a group message from the local database (synchronous call).
refreshTeamMessageReceipt Refresh the number of read and unread messages in group without an asychronous callback
sendTeamMessageReceipt Mark group message as read.
Was this page helpful?
  • Messaging in groups
  • Notification messages
  • Parse notification messages:
  • Do-Not-Disturb
  • Set the Do-Not-Disturb status
  • Do-Not-Disturb
  • Read receipt for group messages
  • API reference