sendMessage

Introduction

Send a message been created.

The method for sending a message is in the core class TencentImSDKPlugin.v2TIMManager.getMessageManager().

It supports sending text, custom, and rich media messages, and all of which belong to the V2TimMessage type.

V2TimMessage can contain different sub-types to indicate different types of messages.

Sending a Text Message

Sending a Custom Message

Sending a Rich Media Message

Flutter for Web

forward messages

Online Message

Group @ Message

Targeted Group Message

Parameter details

Parameter name Parameter type Required Platform Description
id String yes All ID returned after message creation. It needs to be first created through the createXxxMessage API.
receiver String no All userID of the one-to-one message receiver. Just specify receiver for sending one-to-one chat messages.
groupID String no All groupID of the group chat. Just specify groupID for sending group messages.
priority MessagePriorityEnum no All Message priority. Set a higher priority for important messages (such as red packets and gifts) and a lower priority for frequent and unimportant messages (such as likes).
onlineUserOnly bool no All Whether the message can be received by online users only. If it is set to true, the message cannot be loaded when a receiver loading historical messages. This is often used to implement weak prompts, such as "The other party is typing..." and unimportant prompts in a group.
offlinePushInfo OfflinePushInfo no All Offline push information. The title, body and external content carried and shown when a message is pushed offline.
needReadReceipt bool no All Whether a read receipt is supported for the sent group message.
isExcludedFromUnreadCount bool no All Whether the sent message is counted as the unread message of the conversation. If it is set to true, the sent message is not counted as the unread message of the conversation. It defaults to false.
isExcludedFromLastMessage bool no All Whether the sent message is included in the lastMessage of the conversation. If it is set to true, the sent message is not included in the lastMessage of the conversation. It defaults to false.
isSupportMessageExtension boolean no All Whether the sent message supports extension.
cloudCustomData String no All Cloud message data. Extra data of the message that is stored in the cloud and can be accessed by the receiver.
localCustomData String no All Local message data. Extra data of the message that is stored locally. It cannot be accessed by the receiver and will be lost after the application is uninstalled.

Returned template

V2TimValueCallback<V2TimMessage>

{
    code : int
    desc : String
    data : {
      cloudCustomData : String
      customElem : V2TimCustomElem
      elemType : int
      faceElem : V2TimFaceElem
      faceUrl : String
      fileElem : V2TimFileElem
      friendRemark : String
      groupAtUserList : List<String>
      groupID : String
      groupTipsElem : V2TimGroupTipsElem
      id : String
      imageElem : V2TimImageElem
      isExcludedFromLastMessage : bool
      isExcludedFromUnreadCount : bool
      isPeerRead : bool
      isRead : bool
      isSelf : bool
      localCustomData : String
      localCustomInt : int
      locationElem : V2TimLocationElem
      mergerElem : V2TimMergerElem
      messageFromWeb : String
      msgID : String
      nameCard : String
      needReadReceipt : bool
      nickName : String
      offlinePushInfo : V2TimOfflinePushInfo
      priority : int
      progress : int
      random : int
      sender : String
      seq : String
      soundElem : V2TimSoundElem
      status : int
      textElem : V2TimTextElem
      timestamp : int
      userID : String
      videoElem : V2TimVideoElem
    }
}

Return value details

name type description
code int Request result: Error codes. 0 means success.
desc String The description of the failure.
data V2TimMessage The message sent.

Code example

    V2TimValueCallback<V2TimMsgCreateInfoResult> createTextMessageRes =
        await TencentImSDKPlugin.v2TIMManager
            .getMessageManager()
            .createTextMessage(
              text: "test", 
            );
    if (createTextMessageRes.code == 0) {
      String? id = createTextMessageRes.data?.id;
      V2TimValueCallback<V2TimMessage> sendMessageRes =
          await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(
              id: id!, 
              receiver: "userID", 
              groupID: "groupID", 
              priority: MessagePriorityEnum.V2TIM_PRIORITY_DEFAULT, 
              onlineUserOnly:
                  false, 
              isExcludedFromUnreadCount: false, 
              isExcludedFromLastMessage: false, 
              needReadReceipt:
                  false, 
              offlinePushInfo: OfflinePushInfo(), 
              cloudCustomData: "", 
              localCustomData:
                  "" 
              );
      if (sendMessageRes.code == 0) {
      }
    }

results matching ""

    No results matching ""