TencentImSDKPlugin.v2TIMManager.getMessageManager()
.V2TimMessage
type.V2TimMessage
can contain different sub-types to indicate different types of messages.sendMessage
(Details) API is the core API for sending a message. It supports sending all types of messages.sendMessage
.public sendMessage({id,receiver,groupID,onlineUserOnly = false,isExcludedFromLastMessage = false,isExcludedFromUnreadCount = false,needReadReceipt = false,offlinePushInfo,cloudCustomData,localCustomData,priority = MessagePriorityEnum.V2TIM_PRIORITY_NORMAL,}: {id: string;receiver: string;groupID: string;onlineUserOnly?: boolean;isExcludedFromUnreadCount?: boolean;isExcludedFromLastMessage?: boolean;needReadReceipt?: boolean;offlinePushInfo?: V2TimOfflinePushInfo;cloudCustomData?: string;localCustomData?: string;priority?: MessagePriorityEnum;})
Parameter | Definition | Valid for One-to-One Chat | Valid for Group Chat | Description |
id | ID returned after message creation | YES | YES | Create the message using the `createXxxMessage` API in advance. |
receiver | `userID` of the one-to-one message receiver. | YES | NO | Just specify `receiver` for sending one-to-one chat messages. |
groupID | `groupID` of the group chat | NO | YES | Just specify `groupID` for sending group messages. |
priority | Message priority | NO | YES | Set a higher priority for important messages (such as those for red packets and gifts) and a lower priority for frequent and unimportant messages (such as those for likes). |
onlineUserOnly | Whether only online users can receive the message. | YES | YES | If it is set to `true`, the message cannot be pulled by a receiver through historical messages. This is often used to implement weak prompts, such as "The other party is typing..." and unimportant prompts in a group. |
offlinePushInfo | Offline push message | YES | YES | The title and content carried when a message is pushed offline. |
needReadReceipt | Whether a read receipt is supported for the sent group message | NO | YES | Whether a read receipt is supported for the sent group message |
isExcludedFromUnreadCount | Whether the sent message is counted as the unread message of the conversation | YES | YES | If it is set to `true`, the sent message is not counted as the unread message of the conversation. It defaults to `false`. |
isExcludedFromLastMessage | Whether the sent message is included in the `lastMessage` of the conversation | YES | YES | If it is set to `true`, the sent message is not included in the `lastMessage` of the conversation. It defaults to `false`. |
cloudCustomData | Cloud message data | YES | YES | Extra data of the message that is stored in the cloud and can be accessed by the receiver. |
localCustomData | Local message data | YES | YES | 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. |
groupID
and receiver
are set, targeted group messages are sent to receiver
. For more information, see the Sending a Targeted Group Message section of Flutter.sendMessage
mentioned above.createTextMessage
(Details) to create a text message.sendMessage
(Details) to send the message.import { TencentImSDKPlugin } from 'react-native-tim-js';// Create a text messageconst createTextMessage = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createTextMessage("test");if(createTextMessage.code == 0){String id = createTextMessage.data.id;// Send the text messageconst sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "");if(sendMessageRes.code == 0){// Message sent successfully}}
createTextMessage
(Details) to create a text message.sendMessage
(Details) to send the message.// Create a text messageconst text = "test";const atUserList = [];const createTextAtMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createTextAtMessage(text, atUserList);if(createTextAtMessageRes.code == 0){const id = createTextAtMessageRes.data.id;// Send the text messageconst sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "", groupID: "groupID");if(sendMessageRes.code == 0){// Message sent successfully}}
sendMessage
(Details) mentioned above, which supports more sending parameters (such as priority and offline push message) than the ordinary API.createCustomMessage
(Details) to create a custom message.sendMessage
(Details) to send the message.import { TencentImSDKPlugin } from 'react-native-tim-js';// Create a custom messageconst createCustomMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createCustomMessage(data: 'Custom data',desc: 'Custom desc',extension: 'Custom extension',);if(createCustomMessageRes.code == 0){const id = createCustomMessageRes.data.id;// Send the custom messageconst sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "");if(sendMessageRes.code == 0){// Message sent successfully}}
createCustomMessage
(Details) to create a custom message.sendMessage
(Details) to send the message.// Create a custom messageimport { TencentImSDKPlugin } from 'react-native-tim-js';// Create a custom messageconst createCustomMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createCustomMessage(data: 'Custom data',desc: 'Custom desc',extension: 'Custom extension',);if(createCustomMessageRes.code == 0){const id = createCustomMessageRes.data.id;// Send the custom messageconst sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "", groupID: "groupID");if(sendMessageRes.code == 0){// Message sent successfully}}
createXxxMessage
to create a rich media message object of a specified type, where Xxx
indicates the specific message type.sendMessage
(Details) to send the message.import { TencentImSDKPlugin } from 'react-native-tim-js';const imagePath = 'The absolute path of the local image';const createImageMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createImageMessage(imagePath);if (createImageMessageRes.code == 0) {const id = createImageMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// Message sent successfully}}
import { TencentImSDKPlugin } from 'react-native-tim-js';const soundPath = 'The absolute path of the local audio file';const duration = 10; // The audio durationconst createSoundMessageRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createSoundMessage(soundPath,duration// The audio duration);if (createSoundMessageRes.code == 0) {const id = createSoundMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// Message sent successfully}}
import { TencentImSDKPlugin } from 'react-native-tim-js';const videoFilePath = 'The absolute path of the local video file';const type = "mp4"; // The video typeconst duration = 10; // The video durationconst snapshotPath = "The absolute path of the local video thumbnail file";const createVideoMessageRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createVideoMessage(videoFilePath,type, // The video typeduration,// The video durationsnapshotPath,);if (createVideoMessageRes.code == 0) {const id = createVideoMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// Message sent successfully}}
import { TencentImSDKPlugin } from 'react-native-tim-js';filePath: "The absolute path of the local file",const fileName = "Filename";const createFileMessageRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createFileMessage(filePath,fileName,);if (createFileMessageRes.code == 0) {const id = createFileMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// Message sent successfully}}
import { TencentImSDKPlugin } from 'react-native-tim-js';const desc = "Shennan Boulevard, Nanshan District, Shenzhen"const longitude = 34;const latitude = 20;const createLocationMessage =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createLocationMessage(desc,// The location info summarylongitude,// The longitudelatitude, // The latitude);if (createLocationMessage.code == 0) {const id = createLocationMessage.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// Message sent successfully}}
const createFaceMessageRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createFaceMessage(0,"",);if (createFaceMessageRes.code == 0) {const id = createFaceMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// Message sent successfully}}
Was this page helpful?