[+] Get all chats

This commit is contained in:
Pedro Lopez
2019-02-17 23:50:50 -04:00
parent f585cc1c5a
commit 594a65d5e8
2 changed files with 12 additions and 2 deletions

View File

@@ -30,7 +30,8 @@ class Client extends EventEmitter {
await page.goto(WhatsWebURL);
await page.evaluate(ExposeStore);
await page.waitForSelector('._1jjYO'); // Wait for QR Code
// Wait for QR Code
await page.waitForSelector('._1jjYO');
const qr = await page.$eval('._2EZ_m', node => node.getAttribute('data-ref'));
this.emit(Events.QR_RECEIVED, qr);
@@ -48,6 +49,7 @@ class Client extends EventEmitter {
await page.evaluate(LoadExtraProps, model.WAppModel, model.extraFields);
}
// Register events
await page.exposeFunction('onAddMessageEvent', msg => {
if (msg.id.fromMe || !msg.isNewMsg) return;
this.emit(Events.MESSAGE_CREATE, new Message(this, msg));
@@ -81,6 +83,14 @@ class Client extends EventEmitter {
}, chatId, message)
}
async getChats() {
let chats = await this.pupPage.evaluate(() => {
return Store.Chat.serialize()
});
return chats.map(chatData => new Chat(this, chatData));
}
async getChatById(chatId) {
let chat = await this.pupPage.evaluate(chatId => {
return Store.Chat.get(chatId).serialize();

View File

@@ -17,7 +17,7 @@ class Message extends Base {
this.id = data.id;
this.body = data.body;
this.type = data.type;
this.timestame = data.t;
this.timestamp = data.t;
this.from = data.from;
this.to = data.to;
this.author = data.author;