ITUISearchService

ITUISearchService

Methods

searchCloudMessages(options) → {Promise.<any>}

Search cloud messages

【Supported since v2.5.1】
Note 1: This feature is currently in a limited free trial phase. You can contact us through the IM Feature and Purchase Consultation Group to enable the complete feature experience.
Note 2: This interface is locally rate-limited to 2 calls per second.
Note 3: When searching messages in "All Conversations", if the number of matched messages messageCount > 1, the messageList returned by the interface will be [], and you can display "${messageCount} related records" in the UI. If you want to highlight matched messages, please refer to "Specified Search" to 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 will contain that matched message.
Note 5: Community groups, topic groups, and live streaming groups do not support cloud message search.

Examples
// Full search with specified keyword
// - Search for messages containing 'hello'
let promise = TUISearchService.searchCloudMessages({
   keyword: 'hello',
});
// Full search with specified keyword list and message sender
// - Search for messages from 'user1' or 'user2' containing 'hello'
let promise = TUISearchService.searchCloudMessages({
   keyword: 'hello',
   senderUserIDList: ['user1', 'user2'],
});
// Full search with specified keyword and message type
// - Search for messages of type 'text message' or 'custom message' containing 'hello'
let promise = TUISearchService.searchCloudMessages({
   keyword: 'hello',
   messageTypeList: [TUIChatEngine.TYPES.MSG_TEXT, TUIChatEngine.TYPES.MSG_CUSTOM],
});
// Full search for all image messages (keyword list can be empty when sender or message type is specified)
let promise = TUISearchService.searchCloudMessages({
   messageTypeList: [TUIChatEngine.TYPES.MSG_IMAGE],
});
// Full search with specified sender and message type only (keyword list can be empty when sender or message type is specified)
// - Search for messages from 'user1' or 'user2' of type 'text message' or 'custom message'
let promise = TUISearchService.searchCloudMessages({
   senderUserIDList: ['user1', 'user2'],
   messageTypeList: [TUIChatEngine.TYPES.MSG_TEXT, TUIChatEngine.TYPES.MSG_CUSTOM],
});
// Full search with specified keyword and time (past day)
// - Search for messages containing 'hello' or 'where' from the past day
let promise = TUISearchService.searchCloudMessages({
   keyword: 'hello',
   timePosition: Number((new Date().getTime()/1000).toFixed(0)),
   timePeriod: 24 * 60 * 60,
});
promise.then(function(imResponse) {
 // Message 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 then 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 possible cases:
      // - 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 message, you can display it and highlight matched keywords
      console.log(messageList);
    }
}).catch(function(imError) {
   console.error(imError); // Message search failed
});
// Specified conversation with keyword search
// - Search for messages containing 'hello' in 'GROUPPublic001' conversation
let promise = TUISearchService.searchCloudMessages({
   keyword: 'hello',
   conversationID: 'GROUPPublic001'
});
// Specified conversation with message type search (keyword list can be empty when message type is specified)
// - Search for image messages in 'GROUPPublic001' conversation
let promise = TUISearchService.searchCloudMessages({
   conversationID: 'GROUPPublic001',
   messageTypeList: [TUIChatEngine.TYPES.MSG_IMAGE],
});
// Specified conversation with keyword and message type search
// - Search for messages containing 'hello' of type 'text message' or 'custom message' in 'GROUPPublic001' conversation
let promise = TUISearchService.searchCloudMessages({
   keyword: 'hello',
   conversationID: 'GROUPPublic001'
   messageTypeList: [TUIChatEngine.TYPES.MSG_TEXT, TUIChatEngine.TYPES.MSG_CUSTOM],
});
// Specified conversation with keyword and time (past day) search
// - Search for messages containing 'hello' from the past day in 'GROUPPublic001' conversation
let promise = TUISearchService.searchCloudMessages({
   keyword: 'hello',
   conversationID: 'GROUPPublic001'
   timePosition: Number((new Date().getTime()/1000).toFixed(0)),
   timePeriod: 24 * 60 * 60,
});
promise.then(function(imResponse) {
   // Message 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 then 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); // Message search failed
});
Parameters:
Name Type Description
options SearchCloudMessagesParams

Parameters for messages to search

Returns:
Type
Promise.<any>

searchCloudUsers(options) → {Promise.<any>}

Search cloud users

【Supported since v2.5.1】
Search scope: Fuzzy search matching on all users' nicknames (nick), exact search matching on all users' userIDs.
Note 1: This feature is a value-added service requiring purchase of the cloud search plugin. Please click Purchase.
Note 2: User profiles in the returned list are incomplete (only including avatar, nickname, userID, gender, birthday, selfSignature, etc., sufficient for rendering user search results list, excluding custom fields). For detailed user profiles, refer to: getUserProfile.
Note 3: Cloud rate limit is 2 calls/second, local interface call default limit is 20 calls/5 seconds.
Note 4: Maximum search results per request is 100.

Examples
// Search with specified keyword
// - Search for users containing 'test'
let promise = TUISearchService.searchCloudUsers({
   keyword: 'test',
});
// Search with specified keyword list and user gender
// - Search for users containing 'test' with gender 'female'
let promise = TUISearchService.searchCloudUsers({
   keyword: 'test',
   gender: TUIChatEngine.TYPES.GENDER.FEMALE,
});
// Search with specified keyword list and birth date range
// - Search for users containing 'test' with birth date between 19500101 and 20240101
// - Note: When both miniBirthday and maxBirthday are set, miniBirthday must be less than maxBirthday
let promise = TUISearchService.searchCloudUsers({
   keyword: 'test',
   miniBirthday: 19500101,
   maxBirthday: 20240101,
});
// Search with specified keyword list and birth date range
// - Search for users containing 'test' with birth date after 19500101
let promise = TUISearchService.searchCloudUsers({
   keyword: 'test',
   miniBirthday: 19500101,
});
// Search with specified keyword list and birth date range
// - Search for users containing 'test' with birth date before 20240101
let promise = TUISearchService.searchCloudUsers({
   keyword: 'test',
   maxBirthday: 20240101,
});

promise.then(function(imResponse) {
 // User search successful
   const { totalCount, cursor, searchResultList } = imResponse.data;
   console.log(totalCount); // Total number of users matching search criteria
   console.log(cursor); // Starting position for next cloud search, if none then search results are complete
   console.log(searchResultList); // List of users matching search criteria, paginated results, maximum 100 per page based on count setting
   for (let i = 0; i < searchResultList.length; i++) {
      const profileItem = searchResultList[i];
      const { userID, nick, gender, avatar } = profileItem;
      console.log(userID); // User ID
      console.log(nick); // User nickname
      console.log(gender); // User gender
      console.log(avatar); // User avatar
    }
}).catch(function(imError) {
   console.error(imError); // User search failed
});
Parameters:
Name Type Description
options SearchCloudUsersParams

Parameters for users to search

Returns:
Type
Promise.<any>

searchCloudGroups(options) → {Promise.<any>}

Get cloud group list

【Supported since v2.5.1】
Search scope: Fuzzy search matching on all groups' names (name), exact search matching on all groups' groupIDs.
Note 1: This feature is a value-added service requiring purchase of the cloud search plugin. Please click Purchase.
Note 2: Group profiles in the returned list are incomplete (only including groupID, avatar, name, type, memberCount, introduction, ownerID, etc., sufficient for rendering group search results list). For detailed group profiles, refer to: getGroupProfile.
Note 3: Cloud rate limit is 2 calls/second, local interface call default limit is 20 calls/5 seconds.
Note 4: Live streaming groups (TUIChatEngine.TYPES.GRP_AVCHATROOM) are not supported.
Note 5: Maximum search results per request is 100.

Examples
// Search with specified keyword
// - Search for groups containing 'test'
let promise = TUISearchService.searchCloudGroups({
   keyword: 'test',
});
// Search with specified keyword list and group type
// - Search for groups containing 'test' of type 'Public Group (TUIChatEngine.TYPES.GRP_PUBLIC)' or 'Work Group (TUIChatEngine.TYPES.GRP_WORK)'
let promise = TUISearchService.searchCloudGroups({
   keyword: 'test',
   groupTypeList: [TUIChatEngine.TYPES.GRP_PUBLIC, TUIChatEngine.TYPES.GRP_WORK],
});

promise.then(function(imResponse) {
 // Group search successful
   const { totalCount, cursor, searchResultList } = imResponse.data;
   console.log(totalCount); // Total number of groups matching search criteria
   console.log(cursor); // Starting position for next cloud search, if none then search results are complete
   console.log(searchResultList); // List of groups matching search criteria, paginated results, maximum 100 per page based on count setting
   for (let i = 0; i < searchResultList.length; i++) {
      const groupItem = searchResultList[i];
      const { groupID, name, type, avatar, memberCount, introduction, ownerID } = groupItem;
      console.log(groupID); // Group ID
      console.log(name); // Group name
      console.log(type); // Group type
      console.log(avatar); // Group avatar
      console.log(memberCount); // Current number of group members
      console.log(introduction); // Group introduction
      console.log(ownerID); // Group owner's userID
    }
}).catch(function(imError) {
   console.error(imError); // Group search failed
});
Parameters:
Name Type Description
options SearchCloudGroupsParams

Parameters for groups to search

Returns:
Type
Promise.<any>