
import TencentCloudChat from '@tencentcloud/chat';import TIMUploadPlugin from 'tim-upload-plugin';let options = {SDKAppID: 0 // 接入时需要将0替换为您的即时通信 Chat 应用的 SDKAppID};// 创建 SDK 实例// `TencentCloudChat.create()` 方法对于同一个 `SDKAppID` 只会返回同一份实例// SDK 实例通常用 chat 表示let chat = TencentCloudChat.create(options);// 设置 SDK 日志级别// 0: 普通级别,日志量较多,接入时建议使用// 1: release 级别,SDK 输出关键信息,生产环境时建议使用chat.setLogLevel(0);// chat.setLogLevel(1);// 注册腾讯云即时通信 Chat 上传插件chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin});let onMessageReceived = function(event) {// event.name - TencentCloudChat.EVENT.MESSAGE_RECEIVED// event.data - An array to store Messages - [Message]};chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
await chat.login({userID: 'your userID', userSig: 'your userSig'});

let message = chat.createTextMessage({to: 'userB',conversationType: TencentCloudChat.TYPES.CONV_C2C,payload: {text: 'Hello World!'},});await chat.sendMessage(message);
pinConversation。await chat.pinConversation({ conversationID: 'C2CuserB', isPinned: true });
updateMyProfile。await chat.updateMyProfile({avatar: 'http(s)://url/to/image.jpg',});
createGroup。await chat.createGroup({type: TencentCloudChat.TYPES.GRP_WORK,name: 'Sales Plan For The Next Quarter',memberList: [{userID: 'lindal',}, {userID: 'denny',}] // If `memberList` is specified, `userID` must also be specified.});

followUser。await chat.followUser(['celebrity1', 'celebrity2', 'celebrity3']);// 获取我的粉丝列表await chat.getMyFollowersList();
joinGroup 加入直播组,然后使用 createTextMessage 创建消息,然后使用 sendMessage 发布它。await chat.joinGroup({ groupID: 'group1' });let message = chat.createTextMessage({to: 'group1',conversationType: TencentCloudChat.TYPES.CONV_GROUP,payload: {text: 'AMAZING!!!'},});await chat.sendMessage(message);
文档反馈