Methods
sendTextMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send text message
Examples
// Send normal text message
let promise = TUIChatService.sendTextMessage({
payload: {
text: 'Hello world!'
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
// Send text message with custom data
let promise = TUIChatService.sendTextMessage({
payload: {
text: 'Hello world!'
},
cloudCustomData: 'your cloud custom data'
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
text message parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendTextAtMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send text message with @ mention functionality
Example
// Send @ message
let promise = TUIChatService.sendTextAtMessage({
payload: {
text: '@denny @lucy @everyone Dinner tonight, please reply 1 if received',
atUserList: ['denny', 'lucy', TUIChatEngine.TYPES.MSG_AT_ALL] // 'denny' 'lucy' are userIDs, not nicknames
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
text message with @ mention parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendImageMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send image message
Example
// Send image message
let promise = TUIChatService.sendImageMessage({
payload: {
file: file
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
image message parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendAudioMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send audio message
Example
// Send audio message
let promise = TUIChatService.sendAudioMessage({
payload: {
file: file
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
audio message parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendVideoMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send video message
Example
// Send video message
let promise = TUIChatService.sendVideoMessage({
payload: {
file: file
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
video message parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendFileMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send file message
Example
// Send file message
let promise = TUIChatService.sendFileMessage({
payload: {
file: file
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
file message parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendCustomMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send custom message
Example
// Send custom message
let promise = TUIChatService.sendCustomMessage({
payload: {
data: 'dice', // Used to identify this message as a dice type message
description: String(random(1,6)), // Get dice points
extension: ''
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
custom message parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendFaceMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send emoji message
Example
// Send custom message
let promise = TUIChatService.sendFaceMessage({
payload: {
index: 1, // Number emoji index, user defined
data: 'tt00' // String additional data
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
emoji message parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendLocationMessage(options, sendMessageOptionsopt) → {Promise.<any>}
Send location message
Example
// Send location message
let promise = TUIChatService.sendLocationMessage({
payload: {
description: 'Tencent Building, 10000 Shennan Avenue, Shenzhen',
longitude: 113.941079, // Longitude
latitude: 22.546103 // Latitude
},
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
SendMessageParams |
location message parameters |
|
sendMessageOptions |
SendMessageOptions |
<optional> |
message sending options |
Returns:
- Type
- Promise.<any>
sendForwardMessage(conversationList, messageList, sendForwardMessageOptionsopt) → {Promise.<any>}
Forward message
- Note: Supports both individual and merged forwarding
Examples
// Individual forwarding, forward message1, message2 from current conversation to conversation1, conversation2
let promise = TUIChatService.sendForwardMessage([conversation1, conversation2], [message1, message2]);
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
// Merged forwarding, merge and forward message1, message2 from current conversation to conversation1, conversation2
let promise = TUIChatService.sendForwardMessage([conversation1, conversation2], [message1, message2], { needMerge: true });
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
// Merged forwarding with custom title
const sendForwardMessageOptions = {
needMerge: true,
// Merge forwarding configuration, effective when needMerge = true
mergeInfo: {
title: 'Custom merged message title'
}
}
let promise = TUIChatService.sendForwardMessage([conversation1, conversation2], [message1, message2], sendForwardMessageOptions);
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
conversationList |
Array.<(Conversation|IConversationModel)> |
List of conversations to receive forwarded messages |
|
messageList |
Array.<(Message|MessageModel)> |
List of messages to be forwarded |
|
sendForwardMessageOptions |
SendForwardMessageOptions |
<optional> |
Message sending options |
Returns:
- Type
- Promise.<any>
enterTypingState() → {void}
Start typing
- Note: Only supported in C2C conversations
Example
TUIChatService.enterTypingState();
Returns:
- Type
- void
leaveTypingState() → {void}
End typing
- Note: Only supported in C2C conversations
Example
TUIChatService.leaveTypingState();
Returns:
- Type
- void
sendMessageReadReceipt(messageList) → {Promise.<any>}
Send message read receipt
Example
let promise = TUIChatService.sendMessageReadReceipt([messageModel1, messageModel2, messageModel3]);
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Description |
---|---|---|
messageList |
Array.<MessageModel> |
List of messageModels |
Returns:
- Type
- Promise.<any>
getGroupMessageReadMemberList(options) → {Promise.<any>}
Get group message read (or unread) member list
Examples
// Get read member list
let promise = TUIChatService.getGroupMessageReadMemberList({
message,
filter: 0,
cursor: '', // Pass '' for first pull
count: 30,
});
promise.then(function(response) {
const { isCompleted, cursor, messageID, readUserInfoList } = response;
// isCompleted - true, pull complete; false incomplete
// cursor - Used for continued pulling when isCompleted is false
// messageID - Group message ID
// readUserInfoList - List of group member user information who have read
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
// Get unread member list
let promise = TUIChatService.getGroupMessageReadMemberList({
message,
filter: 1,
cursor: '', // Pass '' for first pull
count: 30,
});
promise.then(function(response) {
const { isCompleted, cursor, messageID, unreadUserInfoList } = response;
// isCompleted - true, pull complete; false incomplete
// cursor - Used for continued pulling when isCompleted is false
// messageID - Group message ID
// unreadUserInfoList - List of group member user information who haven't read
});
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Description |
---|---|---|
options |
GetGroupMessageReadParams |
Parameter options |
Returns:
- Type
- Promise.<any>
getMessageList(optionsopt) → {Promise.<any>}
Interface for paginated pulling of message list for specified conversation, should be called when user enters conversation for first time or when user "pulls to load more messages"
Example
let promise = TUIChatService.getMessageList();
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
GetMessageListParams |
<optional> |
Parameters for getting roaming messages |
Returns:
- Type
- Promise.<any>
downloadMergedMessages(message) → {Promise.<any>}
Download merged messages. If the merged message sent by the sender is large, Chat SDK will store this message in the cloud. When the message receiver views the message, they need to download it from the cloud to local first.
Example
if (message.type === TUIChatEngine.TYPES.MSG_MERGER && message.payload.downloadKey !== '') {
// After successful download, SDK will update message.payload.messageList and other information
let promise = TUIChatService.downloadMergedMessages(message);
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
}
Parameters:
Name | Type | Description |
---|---|---|
message |
Record.<string, any> |
Message object or messageBody of merged message object |
Returns:
- Type
- Promise.<any>
setTranslationLanguage(language) → {void}
Set target language for text message translation
Note: Supported since v2.1.0
Example
TUIChatService.setTranslationLanguage('en');
Parameters:
Name | Type | Description |
---|---|---|
language |
string |
Target language, supports multiple target languages, e.g.: English-"en", Simplified Chinese-"zh", French-"fr", German-"de", etc. |
Returns:
- Type
- void
translateText(options) → {Promise.<any>}
Translate text message
Example
let promise = TUIChatService.translateText({
sourceTextList: ['مرحبًا'],
sourceLanguage: 'auto',
});
promise.then((chatResponse) => {
// Translation successful, translatedTextList and sourceTextList elements correspond one-to-one
const { translatedTextList } = chatResponse.data;
});
Parameters:
Name | Type | Description |
---|---|---|
options |
TranslateTextParams |
Message and configuration information to be translated |
Returns:
- Type
- Promise.<any>
searchCloudMessages(options) → {Promise.<any>}
Search cloud messages
【Supported since v0.1.2】
Note 1: This feature is currently in free trial phase, you can contact us through IM Feature and Purchase Consultation Group to enable full feature experience.
Note 2: This interface has a local rate limit of 2 times/second.
Note 3: When searching messages in "All Conversations", if the number of matched messages messageCount > 1, the interface returns messageList as [], you can display "【${messageCount} related records】" in the UI. If you want to highlight matched messages, please refer to "Specified Search", highlight the messageList returned by the interface.
Note 4: When searching messages in "All Conversations", if the number of matched messages in a conversation = 1, then messageList is that matched message.
Note 5: Community, topic, and live streaming groups do not support cloud message search.
Examples
// Full search, specify keywords
// - Search messages containing 'hello' or 'where'
let promise = TUIChatService.searchCloudMessages({
keywordList: ['hello', 'where'],
});
// Full search, specify keywords and match type
// - Search messages containing both 'hello' and 'where'
let promise = TUIChatService.searchCloudMessages({
keywordList: ['hello', 'where'],
keywordListMatchType: 'and',
});
// Full search, specify keyword list and message sender
// - Search messages from senders 'user1' or 'user2' containing 'hello' or 'where'
let promise = TUIChatService.searchCloudMessages({
keywordList: ['hello', 'where'],
senderUserIDList: ['user1', 'user2'],
});
// Full search, specify keywords and message type
// - Search text messages or custom messages containing 'hello' or 'where'
let promise = TUIChatService.searchCloudMessages({
keywordList: ['hello', 'where'],
messageTypeList: [TUIChatEngine.TYPES.MSG_TEXT, TUIChatEngine.TYPES.MSG_CUSTOM],
});
// Full search, search all image messages (when sender or message type is specified, keyword list can be empty)
let promise = TUIChatService.searchCloudMessages({
messageTypeList: [TUIChatEngine.TYPES.MSG_IMAGE],
});
// Full search, only specify message sender and message type (when sender or message type is specified, keyword list can be empty)
// - Search text messages or custom messages from senders 'user1' or 'user2'
let promise = TUIChatService.searchCloudMessages({
senderUserIDList: ['user1', 'user2'],
messageTypeList: [TUIChatEngine.TYPES.MSG_TEXT, TUIChatEngine.TYPES.MSG_CUSTOM],
});
// Full search, specify keywords and time (past day)
// - Search messages containing 'hello' or 'where' from the past day
let promise = TUIChatService.searchCloudMessages({
keywordList: ['hello', 'where'],
timePosition: Number((new Date().getTime()/1000).toFixed(0)),
timePeriod: 24 * 60 * 60,
});
promise.then(function(imResponse) {
// Search successful
const { totalCount, cursor, searchResultList } = imResponse.data;
console.log(totalCount); // Total number of conversations containing messages matching search criteria
console.log(cursor); // Starting position for next cloud search, if none means search results are complete
console.log(searchResultList); // Messages matching search criteria grouped by conversation ID, paginated results
for (let i = 0; i < searchResultList.length; i++) {
const searchResultItem = searchResultList[i];
const { conversationID, messageCount, messageList } = searchResultItem;
console.log(conversationID); // Conversation ID
console.log(messageCount); // Number of messages matching requirements in current conversation
// When searching "All Conversations", messageList will have two possibilities:
// - If matched messages in a conversation > 1, messageList will be empty, you can display "messageCount related records" in UI
// - If matched messages in a conversation = 1, messageList will contain that matched message, you can display it in UI and highlight matched keywords
console.log(messageList);
}
}).catch(function(imError) {
console.error(imError); // Search failed
});
// Specified conversation, specified keyword search
// - Search messages containing 'hello' or 'where' in conversation 'GROUPPublic001'
let promise = TUIChatService.searchCloudMessages({
keywordList: ['hello', 'where'],
conversationID: 'GROUPPublic001'
});
// Specified conversation, specified message type search (when sender or message type is specified, keyword list can be empty)
// - Search image messages in conversation 'GROUPPublic001'
let promise = TUIChatService.searchCloudMessages({
conversationID: 'GROUPPublic001',
messageTypeList: [TUIChatEngine.TYPES.MSG_IMAGE],
});
// Specified conversation, specified keywords and message type search
// - Search text messages or custom messages containing 'hello' or 'where' in conversation 'GROUPPublic001'
let promise = TUIChatService.searchCloudMessages({
keywordList: ['hello', 'where'],
conversationID: 'GROUPPublic001'
messageTypeList: [TUIChatEngine.TYPES.MSG_TEXT, TUIChatEngine.TYPES.MSG_CUSTOM],
});
// Specified conversation, specified keywords and time (past day) search
// - Search messages containing 'hello' or 'where' from the past day in conversation 'GROUPPublic001'
let promise = TUIChatService.searchCloudMessages({
keywordList: ['hello', 'where'],
conversationID: 'GROUPPublic001'
timePosition: Number((new Date().getTime()/1000).toFixed(0)),
timePeriod: 24 * 60 * 60,
});
promise.then(function(imResponse) {
// Search successful
const { totalCount, cursor, searchResultList } = imResponse.data;
console.log(totalCount); // Total number of messages matching search criteria
console.log(cursor); // Starting position for next cloud search, if none means search results are complete
console.log(searchResultList); // Search results for current conversation
const { conversationID, messageCount, messageList } = searchResultList[0];
console.log(conversationID); // Conversation ID
console.log(messageCount); // Number of messages matching requirements in current conversation
console.log(messageList); // List of all messages matching search criteria in this conversation
}).catch(function(imError); {
console.error(imError); // Search failed
});
Parameters:
Name | Type | Description |
---|---|---|
options |
SearchCloudMessagesParams |
Parameters for messages to be searched |
Returns:
- Type
- Promise.<any>
addMessageReaction(message, reactionID) → {Promise.<any>}
Add message reaction
Example
let promise = TUIChatService.addMessageReaction(message, 'smile');
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Description |
---|---|---|
message |
MessageModel |
Message instance Model |
reactionID |
string |
Message reaction ID |
Returns:
- Type
- Promise.<any>
removeMessageReaction(message, reactionID) → {Promise.<any>}
Remove message reaction
Example
let promise = TUIChatService.removeMessageReaction(message, 'smile');
promise.catch((error) => {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Description |
---|---|---|
message |
MessageModel |
Message instance Model |
reactionID |
string |
Message reaction ID |
Returns:
- Type
- Promise.<any>
getAllUserListOfMessageReaction(options) → {Promise.<any>}
Paginated get user list for specified message reaction
Example
let promise = TUIChatService.getAllUserListOfMessageReaction({
message: message,
reactionID: 'smile',
nextSeq: 0,
count: 100,
});
promise.then(function(response) {
// Get successful
const { userList, nextSeq, isCompleted } = response.data;
// userList - User information list, containing user's userID, nick, avatar information
// nextSeq - Used for continued pulling, required when paginated pulling
// isCompleted - Indicates whether all user information has been pulled. When isCompleted is true, nextSeq is 0
}).catch(function(error) {
// Business side can catch exceptions through promise.catch for error handling
});
Parameters:
Name | Type | Description |
---|---|---|
options |
GetAllUserListOfMessageReactionParams |
Parameters for paginated getting user list for specified message reaction |
Returns:
- Type
- Promise.<any>
convertVoiceToText(options) → {Promise.<any>}
Voice to text conversion
Examples
// Convert voice to Chinese
let promise = TUIChatService.convertVoiceToText({
message: audioMessageModel,
});
promise.then((chatResponse) => {
const { result } = chatResponse.data;
});
// Convert voice to Japanese
let promise = TUIChatService.convertVoiceToText({
message: audioMessageModel,
language: 'ja-JP',
});
promise.then((chatResponse) => {
const { result } = chatResponse.data;
});
Parameters:
Name | Type | Description |
---|---|---|
options |
ConvertVoiceToTextParams |
Voice to text conversion parameters |
Returns:
- Type
- Promise.<any>
clearHistoryMessage(string) → {Promise.<any>}
Clear local and cloud messages for one-to-one chat or group chat (without deleting conversation)
Example
// Clear history messages for group chat with groupID 'test'
let promise = TUIChatService.clearHistoryMessage('GROUPtest');
promise.then((chatResponse) => {
const { result } = chatResponse.data;
});
Parameters:
Name | Type | Description |
---|---|---|
string |
conversationID |
Conversation ID |
Returns:
- Type
- Promise.<any>