mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Added Contact Model (#34)
This commit is contained in:
@@ -9,6 +9,7 @@ const Util = require('./util/Util');
|
||||
const { WhatsWebURL, UserAgent, DefaultOptions, Events, WAState } = require('./util/Constants');
|
||||
const { ExposeStore, LoadUtils } = require('./util/Injected');
|
||||
const ChatFactory = require('./factories/ChatFactory');
|
||||
const ContactFactory = require('./factories/ContactFactory');
|
||||
const ClientInfo = require('./structures/ClientInfo');
|
||||
const Message = require('./structures/Message');
|
||||
|
||||
@@ -210,6 +211,29 @@ class Client extends EventEmitter {
|
||||
return ChatFactory.create(this, chat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all current contact instances
|
||||
*/
|
||||
async getContacts() {
|
||||
let contacts = await this.pupPage.evaluate(() => {
|
||||
return window.WWebJS.getContacts();
|
||||
});
|
||||
|
||||
return contacts.map(contact => ContactFactory.create(this, contact));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contact instance by ID
|
||||
* @param {string} contactId
|
||||
*/
|
||||
async getContactById(contactId) {
|
||||
let contact = await this.pupPage.evaluate(contactId => {
|
||||
return window.WWebJS.getContact(contactId);
|
||||
}, contactId);
|
||||
|
||||
return ContactFactory.create(this, contact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts an invite by code
|
||||
* @param {string} inviteCode
|
||||
|
||||
Reference in New Issue
Block a user