tencent cloud

Feedback

Web & uni-app & Mini Program

Last updated: 2024-04-23 15:41:13

    Feature Experience

    
    
    

    
    
    

    UI-Included Integration

    Quickly Integrating Message Cloud Search

    Web&H5 Vue2&Vue3
    Uniapp Vue2&Vue3

    Step 1: Integrate TUIKit

    If @tencentcloud/chat-uikit-vue ≥ 2.0.0 is not integrated, follow the Vue2 & Vue3 TUIKit Quick Integration Guide for integration.

    Step 2: Activate the cloud search plugin through the console

    Note:
    Each plugin can be tried for 7 days for free once. The service will be discontinued after the trial. Therefore, you need to purchase the plugin in advance. During the trial, only the content of messages generated after the cloud search feature is activated can be searched, and historical messages cannot be searched. After you purchase the plugin, historical messages will be automatically synchronized and become searchable.

    Step 3: Search for your first message

    After completing Vue2 & Vue3 TUIKit Quick Integration Guide - Step 6: Send your first message, search for the message you just sent.

    Step 1: Integrate TUIKit

    If @tencentcloud/chat-uikit-uniapp ≥ 2.0.6 is not integrated, follow the Uniapp TUIKit Quick Integration Guide for integration.

    Step 2: Activate the cloud search plugin through the console

    Note:
    Each plugin can be tried for 7 days for free once. The service will be discontinued after the trial. Therefore, you need to purchase the plugin in advance. During the trial, only the content of messages generated after the cloud search feature is activated can be searched, and historical messages cannot be searched. After you purchase the plugin, historical messages will be automatically synchronized and become searchable.

    Step 3: Search for your first message

    After completing Uniapp TUIKit Rapid Integration Guide - Step 6: Send for your first message, search for the message you just sent.

    Independently Introducing Message Cloud Search

    Note:
    In the step Quickly Integrating Message Cloud Search above, all features of message cloud search are introduced by default, and therefore do not need to be introduced independently.
    If you want to independently introduce the <TUISearch> for message cloud search, see the following guide.
    Web&H5 Vue2&Vue3
    Uniapp Vue2&Vue3

    Prerequisites

    If @tencentcloud/chat-uikit-vue ≥ 2.0.0 is not integrated, follow the Vue2 & Vue3 TUIKit Quick Integration Guide for integration.

    Introducing <TUISearch>

    On the .vue page where you need the message cloud search feature, introduce <TUISearch>.
    <TUISearch> Parameter Description
    Parameter Name
    Type
    Description
    searchType
    String
    global: Global search (default)
    conversation: Search in conversation
    <TUISearch> Effect Display
    <TUISearch searchType="global" />
    <TUISearch searchType="conversation" />
    
    
    
    
    
    
    Using TUISearch
    import { TUISearch } from "@tencentcloud/chat-uikit-vue";
    // Global search
    <TUISearch searchType="global" />
    // Search in conversation
    <TUISearch searchType="conversation" />
    Deleting the TUISearch Introduced by Default
    TUIKit comes with <TUISearch> integrated by default. If you prefer not to use the default integration method, you can comment out <TUISearch> in TUIKit/index.vue.
    Uniapp TUISearch supports two integration methods: component and page.

    Prerequisites

    If @tencentcloud/chat-uikit-uniapp ≥ 2.0.6 is not integrated, follow the Uniapp TUIKit Quick Integration Guide for integration.
    Component Integration
    Page-Based Introduction
    On the .vue page where you need the message cloud search feature, introduce <TUISearch>.
    <TUISearch> Parameter Description
    Parameter Name
    Type
    Description
    searchType
    String
    global: Global search
    conversation: Search in conversation (default)
    <TUISearch> Effect Display
    <TUISearch searchType="global" />
    <TUISearch searchType="conversation" />
    
    
    Using TUISearch
    // The following is just an example path. Replace it with the path of your project.
    import { TUISearch } from "/TUIKit/components/TUISearch/index.vue";
    // Global search
    <TUISearch searchType="global" />
    // Search in conversation
    <TUISearch searchType="conversation" />
    Deleting the TUISearch Introduced by Default
    TUIKit comes with <TUISearch> integrated by default. If you prefer not to use the default integration method, you can comment out <TUISearch> in TUIKit/components/TUIConversation/index.vue.
    Adding a TUISearch Page in pages.json
    {
    "pages": [
    ...,
    {
    "path": "TUIKit/components/TUISearch/index",
    "style": {
    "navigationBarTitleText": "Chat records"
    }
    }
    ],
    ...
    }
    Navigating to the TUISearch Page
    uni.navigateTo({
    url: "/TUIKit/components/TUISearch/index",
    });

    Advanced Guide

    Adding Search Message Types

    Original "Global Search" message type list
    "Global Search" message type list after addition
    
    
    
    
    
    
    Directory location: src/TUIKit/components/TUISearch/search-type-list.ts
    searchMessageTypeList contains all the definitions in the "Search Message Types" tab. To add search message types not defined in searchMessageTypeList, follow the structure below to add them in searchMessageTypeList:
    [keyName: string]: {
    key: string; // Specifies the key of the search message type, which must be unique.
    label: string; // Specifies the label for rendering search message type.
    value: Array<string>; // Specifies the actual search list for the search message type.
    };
    // For example, to search for custom messages
    export const searchMessageTypeList = {
    ...
    customMessage: {
    key: "customMessage", // Specifies the key of the search message type, which must be unique.
    label: "Custom", // Specifies the label for rendering search message type.
    value: [TUIChatEngine.TYPES.MSG_CUSTOM], // Specifies the actual search list for the search message type.
    }
    };
    Due to TUIKit's use of i18next for internationalization, if you want to claim a new label, add the corresponding international entries in src/TUIKit/locales/zh_cn/TUISearch.ts and src/TUIKit/locales/en/TUISearch.ts for translation.
    To add a type defined in searchMessageTypeList to Global Search Type List or Search in conversation Type List, you just need to add its key to globalSearchTypeKeys or conversationSearchTypeKeys.
    // For example, to apply the newly defined customMessage to the "Global Search" message type list
    export const globalSearchTypeKeys = [..., "customMessage"];
    // For example, to apply the newly defined customMessage to the "Search in conversation" message type list
    export const conversationSearchTypeKeys = [..., "customMessage"];

    Adding a Time Range for Message Cloud Search

    Original "Global Search" time range list
    "Global Search" time range list after addition
    
    
    
    
    
    
    Directory location: src/TUIKit/components/TUISearch/search-time-list.ts
    searchMessageTimeList contains all definitions in the "Search Time Range" tab. To add search time range types not defined in searchMessageTimeList, follow the structure below to add them in searchMessageTimeList:
    [keyName: string]: {
    key: string; // Specifies the key of the message search time range, which must be unique.
    label: string; // Specifies the label for rendering the message search time range.
    value: {
    timePosition: number; // Specifies the start position for message search time range. The default value is 0, indicating searching from the current time.
    timePeriod: number; // Specifies the time range to search backward from timePosition.
    };
    };
    // For example, to search for messages in the time range of "last two days"
    export const searchMessageTimeList = {
    ...
    twoDay: {
    key: "twoDay", // Specifies the key of the message search time range, which must be unique.
    label: "Two days", // Specifies the label for rendering the message search time range.
    value: {
    timePosition: 0, // Specifies the start position for message search time range. The default value is 0, indicating searching from the current time.
    timePeriod: 2 * oneDay; // Specifies the time range to search backward from timePosition.
    },
    },
    };
    Due to TUIKit's use of i18next for internationalization, if you want to claim a new label, add the corresponding international entries in src/TUIKit/locales/zh_cn/TUISearch.ts and src/TUIKit/locales/en/TUISearch.ts for translation.
    

    Integration Without UI

    The following is the no-UI integration solution for message cloud search:

    Feature Description

    Message cloud search can enhance the use of IM SDK by allowing users to locate the expected content from complex information directly, easily, and conveniently. It can also serve as an operations tool by adding guide to relevant content, making it concise and efficient.
    Note:
    The message cloud search feature is provided starting from v3.1.0.
    This API is locally limited to 2 calls per second.
    When you search for messages in all conversations, if the number of matched messages, that is, messageCount, is greater than 1, then messageList returned by the API will be [], and [<5>${messageCount} <5/> records] can be displayed on the UI. If you want to highlight the matched messages, follow the instructions in <7>Specified Search</7> and highlight the returned <9>messageList</9>.
    When you search for messages in all conversations, if the number of matched messages in a conversation equals 1, then messageList is the matched message.
    Communities, topics, and live broadcast groups do not support cloud message search.

    Searching for Cloud Messages

    API
    chat.searchCloudMessages(options);
    Parameter
    The options parameter is of the Object type, containing the following attributes:
    Name
    
    Type
    
    Description
    
    keywordList
    Array | undefined
    Specifies the keyword list. Up to 5 keywords are supported.
    Note:
    When neither the message sender nor the message type is specified, the keyword list must not be empty; otherwise, it can be empty.
    keywordListMatchType
    String | undefined
    Specifies the match type of the keyword list.
    or: Specifies search in the "OR" relationship (default).
    and: Specifies search in the "AND" relationship.
    senderUserIDList
    Array | undefined
    Specifies messages sent by the userID. Up to 5 IDs are supported.
    messageTypeList
    Array | undefined
    Specifies the set of message types to be searched. All types are searched by default.
    If this parameter is not specified, all supported types of messages (TencentCloudChat.TYPES.MSG_FACE, TencentCloudChat.TYPES.MSG_GRP_TIP, and TencentCloudChat.TYPES.MSG_GRP_SYS_NOTICE are not supported) are searched.
    When this parameter is specified, see TencentCloudChat.TYPES for details.
    conversationID
    String | undefined
    Specifies whether to search for messages in "all conversations" or in the "specified conversation". If this parameter is not specified, all conversations are searched by default. The default value is all conversations. The composition of conversation ID:
    C2C${userID} (for one-on-one chat)
    GROUP${groupID} (for group chat)
    Communities, topics, and live broadcast groups do not support cloud message search.
    timePosition
    Number | undefined
    Specifies the start time point for search, in the unit of seconds. The default value is 0, indicating searching from the current time.
    timePeriod
    Number | undefined
    Specifies the range of past time starting from the start time point, in the unit of seconds. The default value is 0, indicating no time limit. The value 24 60 60 indicates the last day.
    cursor
    String | undefined
    Specifies the start position for each cloud search. Do not specify cursor for the first search. For subsequent searches, fill in the value of cursor returned by the last call to the searchCloudMessages API.
    Note:
    During a full search, the cursor's validity period is 2 minutes.
    Return Values
    Promise
    Name
    
    Type
    
    Description
    
    totalCount
    Number
    In case of search in a specified conversation, the total number of messages that meet the search criteria will be returned.
    In case of search in all conversations, the total number of conversations containing messages that meet the search criteria will be returned.
    searchResultList
    Array
    Messages that meet the search criteria are grouped by conversation ID.
    cursor
    String
    Specifies the cursor needed when continuing to retrieve through the search API.
    Where, searchResultList is a list containing search result objects, with parameters described as follows:
    Name
    
    Type
    
    Description
    
    conversationID
    String
    conversation ID.
    messageCount
    Number
    Specifies the total number of messages matching the criteria found in the current conversation.
    messageList
    Array
    Specifies the list of all messages in the current conversation that meet the search criteria.
    Note:
    1. In case of search in a specified conversation, messageList is the list of all messages in this conversation that meet the search criteria.
    2. In case of search in all conversations, the number of messages contained in messageList may have the following two possibilities:
    If the number of matched messages, that is, messageCount, is greater than 1, messageList returned by the API is []. [${messageCount} records] can be displayed on the UI. If you want to highlight the matched messages, see Specified Search and highlight the messageList returned by the API.
    If the number of matched messages in a conversation equals 1, then messageList is the matched message.

    Searching Messages in All Conversations

    Search by specifying keywords without specifying conversationID.
    Sample
    // Perform full search with specified keywords.
    // - Search for messages containing 'hello' or 'where are you'
    let promise = chat.searchCloudMessages({
    keywordList: ['hello', 'where are you']
    });
    promise.then(function(imResponse) {
    // Messages searched successfully.
    const { totalCount, cursor, searchResultList } = imResponse.data;
    console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.
    console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.
    console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.
    for (let i = 0; i < searchResultList.length; i++) {
    const searchResultItem = searchResultList[i];
    const { conversationID, messageCount, messageList } = searchResultItem;
    console.log(conversationID); // Specifies the conversation ID.
    console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.
    // In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:
    // - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.
    // - If the number of messages matched in a conversation equals 1, then messageList is the matched message.
    // This message can be displayed on the UI and the matching keywords are highlighted.
    console.log(messageList);
    }
    }).catch(function(imError) {
    console.error(imError); // Failed to search for messages.
    });

    Searching for the Messages in the Specified Conversation

    Specify conversationID, search by specifying keywords.
    Sample
    // Search in a specified conversation by specifying keywords.
    // - Search for messages containing 'hello' or 'where are you' in the 'GROUPPublic001' conversation.
    let promise = chat.searchCloudMessages({
    keywordList: ['hello', 'where are you'],
    conversationID: 'GROUPPublic001'
    });
    promise.then(function(imResponse) {
    // Messages searched successfully.
    const { totalCount, cursor, searchResultList } = imResponse.data;
    console.log(totalCount); // Specifies the total number of messages that meet the search criteria.
    console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.
    console.log(searchResultList); // Specifies message search results of the current conversation.
    const { conversationID, messageCount, messageList } = searchResultList[0];
    console.log(conversationID); // Specifies the conversation ID.
    console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.
    console.log(messageList); // Specifies the list of all messages in the current conversation that meet the search criteria.
    }).catch(function(imError); {
    console.error(imError); // Failed to search for messages.
    });

    Searching for Custom Messages

    1. When using the createCustomMessage API to create a custom message, you need to place the text to search in the description parameter. Keywords with description are supported.
    2. You can specify messageTypeList as TencentCloudChat.TYPES.MSG_CUSTOM for categorized search, which will search for all custom messages.
    Sample
    // Perform full search with specified keywords and message types.
    // - Search for messages of type 'custom message', where the description contains 'hello' or 'where are you.'
    let promise = chat.searchCloudMessages({
    keywordList: ['hello', 'where are you'],
    messageTypeList: [TencentCloudChat.TYPES.MSG_CUSTOM],
    });
    promise.then(function(imResponse) {
    // Messages searched successfully.
    const { totalCount, cursor, searchResultList } = imResponse.data;
    console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.
    console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.
    console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.
    for (let i = 0; i < searchResultList.length; i++) {
    const searchResultItem = searchResultList[i];
    const { conversationID, messageCount, messageList } = searchResultItem;
    console.log(conversationID); // Specifies the conversation ID.
    console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.
    // In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:
    // - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.
    // - If the number of messages matched in a conversation equals 1, then messageList is the matched message.
    // This message can be displayed on the UI and the matching keywords are highlighted.
    console.log(messageList);
    }
    }).catch(function(imError) {
    console.error(imError); // Failed to search for messages.
    });

    Searching for Rich Media Messages

    Rich media messages include files, images, audios, and video messages.
    1. For file messages, the filename is usually displayed on the UI. If createFileMessage is called to create a file message with the fileName parameter, fileName will act as the content to be searched for and match the search keywords.
    2. For image, audio, and video messages, there is no specific name like fileName, and the UI usually displays a thumbnail or duration. Specifying keywordList for search is ineffective in this case.
    3. You can specify messageTypeList as TencentCloudChat.TYPES.MSG_IMAGE/TencentCloudChat.TYPES.MSG_AUDIO/TencentCloudChat.TYPES.MSG_FILE for categorized search, which will reveal all messages of the specified types.
    Sample
    // Perform full search by only specifying the message sender and message types (when the sender and message types are specified, the keyword list can be empty).
    // - Search for messages from 'user1' or 'user2', and messages of type 'Image Message', 'Voice Message', or 'File Message'.
    let promise = chat.searchCloudMessages({
    senderUserIDList: ['user1', 'user2'],
    messageTypeList: [
    TencentCloudChat.TYPES.MSG_IMAGE,
    TencentCloudChat.TYPES.MSG_AUDIO,
    TencentCloudChat.TYPES.MSG_FILE
    ],
    });
    promise.then(function(imResponse) {
    // Messages searched successfully.
    const { totalCount, cursor, searchResultList } = imResponse.data;
    console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.
    console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.
    console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.
    for (let i = 0; i < searchResultList.length; i++) {
    const searchResultItem = searchResultList[i];
    const { conversationID, messageCount, messageList } = searchResultItem;
    console.log(conversationID); // Specifies the conversation ID.
    console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.
    // In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:
    // - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.
    // - If the number of messages matched in a conversation equals 1, then messageList is the matched message.
    // This message can be displayed on the UI and the matching keywords are highlighted.
    console.log(messageList);
    }
    }).catch(function(imError) {
    console.error(imError); // Failed to search for messages.
    });
    

    Searching for Geographical Location Messages

    1. Messages containing latitude, longitude, description and keywords are supported.
    2. You can specify messageTypeList as TencentCloudChat.TYPES.MSG_LOCATION for categorized search, which will search for all geographical location messages.
    Sample
    // Perform full search with specified keywords and message types.
    // - Search for messages of type 'Geographical Location', where the latitude, longitude, and description contains 'hello' or 'where are you'.
    let promise = chat.searchCloudMessages({
    keywordList: ['hello', 'where are you'],
    messageTypeList: [TencentCloudChat.TYPES.MSG_LOCATION],
    });
    promise.then(function(imResponse) {
    // Messages searched successfully.
    const { totalCount, cursor, searchResultList } = imResponse.data;
    console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.
    console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.
    console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.
    for (let i = 0; i < searchResultList.length; i++) {
    const searchResultItem = searchResultList[i];
    const { conversationID, messageCount, messageList } = searchResultItem;
    console.log(conversationID); // Specifies the conversation ID.
    console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.
    // In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:
    // - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.
    // -If the number of messages matched in a conversation equals 1, then messageList is the matched message.
    // This message can be displayed on the UI and the matching keywords are highlighted.
    console.log(messageList);
    }
    }).catch(function(imError) {
    console.error(imError); // Failed to search for messages.
    });

    Searching for Merger Messages

    1. When using the createMergerMessage API to create a merger message, you need to place the search text in the title or abstractList parameters. Keywords title and abstractList are supported.
    2. You can specify messageTypeList as TencentCloudChat.TYPES.MSG_MERGER for categorized search, which will search for all merger messages.
    Sample
    // Perform full search with specified keywords and message types.
    // - Search for message types marked as ‘Merger Message’, and messages containing ‘hello’ or ‘where are you?’ in their title or abstractList.
    let promise = chat.searchCloudMessages({
    keywordList: ['hello', 'where are you'],
    messageTypeList: [TencentCloudChat.TYPES.MSG_MERGER],
    });
    promise.then(function(imResponse) {
    // Messages searched successfully.
    const { totalCount, cursor, searchResultList } = imResponse.data;
    console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.
    console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.
    console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.
    for (let i = 0; i < searchResultList.length; i++) {
    const searchResultItem = searchResultList[i];
    const { conversationID, messageCount, messageList } = searchResultItem;
    console.log(conversationID); // Specifies the conversation ID.
    console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.
    // In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:
    // - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.
    // - If the number of messages matched in a conversation equals 1, then messageList is the matched message.
    // This message can be displayed on the UI and the matching keywords are highlighted.
    console.log(messageList);
    }
    }).catch(function(imError) {
    console.error(imError); // Failed to search for messages.
    });
    
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support