Skip to main content

Search Messages

Search by Keyword

Search for messages in a specific conversation by keyword.

Method


searchMessages(
type: RCIMIWConversationType,
targetId: string,
channelId: string,
keyword: string,
startTime: number,
count: number,
callback: IRCIMIWSearchMessagesCallback
): Promise<number>;

Parameter Description

ParameterTypeDescription
typeRCIMIWConversationTypeConversation type
targetIdstringConversation ID
channelIdstringChannel ID, only supported for ultra groups. Pass null for other conversation types.
keywordstringKeyword to search for
startTimenumberSearch for messages before this timestamp. Pass 0 to start searching from the latest message, moving backward in time.
countnumberNumber of messages to return. Must be greater than 0 and less than or equal to 50.
callbackIRCIMIWSearchMessagesCallbackCallback for the operation result.

Return Value

Return ValueDescription
numberStatus code of the operation. 0 indicates success. For specific results, implement the callback interface. Non-zero values indicate failure, and the callback will not be triggered. Refer to the error codes for details.

Code Example


const callback = {
onSuccess: (t: Array<RCIMIWMessage>) => {
//...
},
onError: (code: number) => {
//...
},
};
let code = await engine.searchMessages(type, targetId, channelId, keyword, startTime, count, callback);

Search Messages by Time Range

Method


searchMessagesByTimeRange(
type: RCIMIWConversationType,
targetId: string,
channelId: string,
keyword: string,
startTime: number,
endTime: number,
offset: number,
count: number,
callback: IRCIMIWSearchMessagesByTimeRangeCallback
): Promise<number>;

Parameter Description

ParameterTypeDescription
typeRCIMIWConversationTypeConversation type
targetIdstringConversation ID
channelIdstringChannel ID, only supported for ultra groups. Pass null for other conversation types.
keywordstringKeyword to search for
startTimenumberStart time
endTimenumberEnd time
offsetnumberOffset
countnumberNumber of search results to return. Must be greater than 0 and less than or equal to 50.
callbackIRCIMIWSearchMessagesByTimeRangeCallbackCallback for the operation result.

Return Value

Return ValueDescription
numberStatus code of the operation. 0 indicates success. For specific results, implement the callback interface. Non-zero values indicate failure, and the callback will not be triggered. Refer to the error codes for details.

Code Example


const callback = {
onSuccess: (t: Array<RCIMIWMessage>) => {
//...
},
onError: (code: number) => {
//...
},
};
let code = await engine.searchMessagesByTimeRange(
type,
targetId,
channelId,
keyword,
startTime,
endTime,
offset,
count,
callback
);

Search Messages by User ID

Method


searchMessagesByUserId(
userId: string,
type: RCIMIWConversationType,
targetId: string,
channelId: string,
startTime: number,
count: number,
callback: IRCIMIWSearchMessagesByUserIdCallback
): Promise<number>;

Parameter Description

ParameterTypeDescription
userIdstringUser ID
typeRCIMIWConversationTypeConversation type
targetIdstringConversation ID
channelIdstringChannel ID, only supported for ultra groups. Pass null for other conversation types.
startTimenumberStart time for the search. Pass 0 to start searching from the latest message, moving backward in time.
countnumberNumber of search results to return. Must be greater than 0 and less than or equal to 50.
callbackIRCIMIWSearchMessagesByUserIdCallbackCallback for the operation result.

Return Value

Return ValueDescription
numberStatus code of the operation. 0 indicates success. For specific results, implement the callback interface. Non-zero values indicate failure, and the callback will not be triggered. Refer to the error codes for details.

Code Example


const callback = {
onSuccess: (t: Array<RCIMIWMessage>) => {
//...
},
onError: (code: number) => {
//...
},
};
let code = await engine.searchMessagesByUserId(userId, type, targetId, channelId, startTime, count, callback);