sendMessage

Introduction

send a message

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.

Parameter details

Parameter name Parameter type Required Description
id string yes ID returned after message creation. It needs to be first created through the createXxxMessage API.
receiver string no userID of the one-to-one message receiver. Just specify receiver for sending one-to-one chat messages.
groupID string no groupID of the group chat. Just specify groupID for sending group messages.
priority MessagePriorityEnum no 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 boolean no 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 V2TimOfflinePushInfo no Offline push information. The title, body and external content carried and shown when a message is pushed offline.
needReadReceipt boolean no Whether a read receipt is supported for the sent group message.
isExcludedFromUnreadCount boolean no 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 boolean no 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.
isSupportMessageExtension boolean no Whether the sent message supports extension.
cloudCustomData string no Cloud message data. Extra data of the message that is stored in the cloud and can be accessed by the receiver.
localCustomData string no 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 : number
    desc : string
    data : {
      msgID: string
      timestamp: number
      progress: number
      sender: string
      nickName: string
      friendRemark: string
      faceUrl: string
      nameCard: string
      groupID: string
      userID: string
      status: number
      elemType: number
      textElem: V2TimTextElem
      customElem: V2TimCustomElem
      imageElem: V2TimImageElem
      soundElem: V2TimSoundElem
      videoElem: V2TimVideoElem
      fileElem: V2TimFileElem
      locationElem: V2TimLocationElem
      faceElem: V2TimFaceElem
      groupTipsElem: V2TimGroupTipsElem
      mergerElem: V2TimMergerElem
      localCustomData: string
      localCustomInt: number
      cloudCustomData: string
      isSelf: boolean
      isRead: boolean
      isPeerRead: boolean
      priority: number
      offlinePushInfo: V2TimOfflinePushInfo
      groupAtUserList: string[]
      seq: string
      random: number
      isExcludedFromUnreadCount: boolean
      isExcludedFromLastMessage: boolean
      id: string
      needReadReceipt: boolean
    }
}

Return value details

name type description
code number Request result: Error codes. 0 means success.
desc string The description of the error. It will be empty if success.
data V2TimMessage The message sent.

Code example

import { TencentImSDKPlugin, MessagePriorityEnum } from 'react-native-tim-js';


const createTextMessageRes = await TencentImSDKPlugin.v2TIMManager
    .getMessageManager()
    .createTextMessage(
        'test'
    );
if (createTextMessageRes.code == 0) {

    const id = createTextMessageRes.data?.id;




    const 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: {},
            cloudCustomData: '',
            localCustomData: '',
        });
    if (sendMessageRes.code === 0) {

    }
}

results matching ""

    No results matching ""