Message Type | Rendering |
Text Message | |
Image Message | |
Sound Message | |
Video Message | |
File Message | |
src/TUUIKit/components/TUIMessage/element/custom_element.tsx
file.import React from 'react';import {Text} from 'react-native';import type {V2TimMessage} from 'react-native-tim-js/lib/typescript/src/interface';export const CustomElement = (props: {message: V2TimMessage}) => {const {message} = props; //message contains all the properties of the current custom message, and you can change the rendering result according to your custom requirements.console.log(message);return <Text>["custom message"]</Text>;};
import { TencentImSDKPlugin } from 'react-native-tim-js';// create custom messageconst createCustomMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createCustomMessage({data: '自定义data',desc: '自定义desc',extension: '自定义extension',});if (createCustomMessageRes.code === 0) {const id = createCustomMessageRes.data?.id;// send custom message// When sendingMessage, if you only fill in the receiver, you will send a single chat message for individual users// If only the groupID is filled in, you will send a group message// If you fill in the receiver and groupID, it will be sent to individual users in the group, and the message will be displayed in the group chat, and only the specified receiver can see itconst sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage({ id: id!, receiver: 'userID', groupID: 'groupID' });if (sendMessageRes.code === 0) {// successsendMessageRes.data?.customElem?.data; //custom datasendMessageRes.data?.customElem?.desc; //custom descsendMessageRes.data?.customElem?.extension; //custom extension}}
Was this page helpful?