
import TencentCloudChat from '@tencentcloud/chat';import TIMUploadPlugin from 'tim-upload-plugin';let options = {SDKAppID: 0 // Replace 0 with the SDKAppID of your Chat application when connecting.};// Create an SDK instance.// The `TencentCloudChat.create()` method returns the same instance for the same `SDKAppID`.// The SDK instance is usually represented by chat.let chat = TencentCloudChat.create(options);// Set the SDK log level.// 0: Common level. You are advised to use this level during access as it covers more logs.// 1: Release level. You are advised to use this level for key information in a production environment.chat.setLogLevel(0);// chat.setLogLevel(1);// Register the Tencent Cloud Chat upload plugin.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']);// Get my follower listawait chat.getMyFollowersList();
joinGroup to join a live group and then use createTextMessage to create a message and then use sendMessage to post it.await chat.joinGroup({ groupID: 'group1' });let message = chat.createTextMessage({to: 'group1',conversationType: TencentCloudChat.TYPES.CONV_GROUP,payload: {text: 'AMAZING!!!'},});await chat.sendMessage(message);
Feedback