Skip to content

Commit

Permalink
feat: Added listChats function
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jun 2, 2023
1 parent 8329e70 commit e145688
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/api/layers/retriever.layer.ts
Expand Up @@ -27,6 +27,7 @@ import {
Wid,
} from '../model';
import { SenderLayer } from './sender.layer';
import { ChatListOptions } from '@wppconnect/wa-js/dist/chat';

export class RetrieverLayer extends SenderLayer {
constructor(public page: Page, session?: string, options?: CreateConfig) {
Expand Down Expand Up @@ -124,6 +125,50 @@ export class RetrieverLayer extends SenderLayer {
}
}

/**
* Return list of chats
* * @example
* ```javascript
* // All chats
* const chats = await client.chatList();
*
* // Some chats
* const chats = client.chatList({count: 20});
*
* // 20 chats before specific chat
* const chats = client.chatList({count: 20, direction: 'before', id: '[number]@c.us'});
*
* // Only users chats
* const chats = await client.chatList({onlyUsers: true});
*
* // Only groups chats
* const chats = await client.chatList({onlyGroups: true});
*
* // Only with label Text
* const chats = await client.chatList({withLabels: ['Test']});
*
* // Only with label id
* const chats = await client.chatList({withLabels: ['1']});
*
* // Only with label with one of text or id
* const chats = await client.chatList({withLabels: ['Alfa','5']});
* ```
* @category Chat
* @returns array of [Chat]
*/
public async listChats(options?: ChatListOptions): Promise<Chat[]> {
return await evaluateAndReturn(
this.page,
async ({ options }) => {
const chats = await WPP.chat.list(options);

const serialized = chats.map((c) => WAPI._serializeChatObj(c));
return serialized;
},
{ options }
);
}

/**
* Checks if a number is a valid WA number
* @category Contact
Expand Down

0 comments on commit e145688

Please sign in to comment.