Resend and forward a message

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

The MessageService class provides methods used to forward and resend messaegs and corresponding listeners. Sending forwarded messages is the same as sending different types of messages (such as text, audio, and video). You must construct the message to be forwarded and then call the sendMessage method to send it to the target user.

Except for notification messages, other types of messages can be forwarded to other sessions.


API rate limit

The method of sending a message (sendMessage) can be called up to 300 times per minute by default.

Resend a message

If a message fails to be delivered, users can resend the message. The sendMessage method is used to send or resend a message. If the resend parameter is set to true, the message is resent.

Forward a message

The SDK can forward all types of message except notifications and messages for audio and video call events.

API call sequence diagram

  • The implementation of forwarding different types of messages are similar. This section only uses forwarding a text message as an example.
  • The sequence diagrams in this article may display abnormally due to network problems. To fix the displayed problem, refresh the current page.
uml diagram


This section describes the message interaction of users A, B, and C in the previous sequence diagram and introduces the implementation of forwarding a message.

  1. User C registers the onMessage event stream to listen for message receiving.

  2. User B receives the message sent by user A and calls forwardMessage to forward the received message by assigning the received message to the message parameter and user C's IM account ID to the sessionId parameter.

    Sample code:

dartNIMResult<NIMMessage> message = await MessageBuildercreateTextMessage(sessionId: '123', sessionType: NIMSessionTypep2p, text: ' Forward ');
if (message.isSuccess) {
    NimCore.instance.messageService.forwardMessage(!, '123', NIMSessionType.p2p);
  1. The onMessage event triggers the Stream the callback. User C receives the forwarded message returned by this callback.

API reference

onMessage Register the event stream of receiving message and listen to message receiving.
forwardMessage Forward a message.
Was this page helpful?
  • Prerequisites
  • API rate limit
  • Resend a message
  • Forward a message
  • API call sequence diagram
  • Implementation
  • API reference