add searchMessages method (#586)

* add searchMessages method

* fix typing

* fix typing

* remove unused statement

Co-authored-by: Pedro S. Lopez <pslamoros@hotmail.com>
This commit is contained in:
Wictor Nogueira
2021-06-01 22:54:27 -03:00
committed by GitHub
parent 0a061f982c
commit b895437458
2 changed files with 21 additions and 0 deletions

3
index.d.ts vendored
View File

@@ -99,6 +99,9 @@ declare namespace WAWebJS {
/** Send a message to a specific chatId */
sendMessage(chatId: string, content: MessageContent, options?: MessageSendOptions): Promise<Message>
/** Searches for messages */
searchMessages(query: string, options?: { chatId?: string, page?: number, limit?: number }): Promise<Message[]>
/** Marks the client as online */
sendPresenceAvailable(): Promise<void>

View File

@@ -510,6 +510,24 @@ class Client extends EventEmitter {
return new Message(this, newMessage);
}
/**
* Searches for messages
* @param {string} query
* @param {Object} [options]
* @param {number} [options.page]
* @param {number} [options.limit]
* @param {string} [options.chatId]
* @returns {Promise<Message[]>}
*/
async searchMessages(query, options = {}) {
const messages = await this.pupPage.evaluate(async (query, page, count, remote) => {
const { messages } = await window.Store.Msg.search(query, page, count, remote);
return messages.map(msg => window.WWebJS.getMessageModel(msg));
}, query, options.page, options.limit, options.chatId);
return messages.map(msg => new Message(this, msg));
}
/**
* Get all current chat instances
* @returns {Promise<Array<Chat>>}