mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
feat: get profile pic url by user ID
This moves the function from Contact to Client to enable getting profile picture without requiring a conversation before. The old function is still available on Contact for convenience and backwards-compatibility.
This commit is contained in:
@@ -547,6 +547,18 @@ class Client extends EventEmitter {
|
||||
}, chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contact ID's profile picture URL, if privacy settings allow it
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async getProfilePicUrl(contactId) {
|
||||
const profilePic = await this.pupPage.evaluate((contactId) => {
|
||||
return window.Store.Wap.profilePicFind(contactId);
|
||||
}, contactId);
|
||||
|
||||
return profilePic ? profilePic.eurl : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force reset of connection state for the client
|
||||
*/
|
||||
|
||||
@@ -103,11 +103,7 @@ class Contact extends Base {
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async getProfilePicUrl() {
|
||||
const profilePic = await this.client.pupPage.evaluate((contactId) => {
|
||||
return window.Store.Wap.profilePicFind(contactId);
|
||||
}, this.id._serialized);
|
||||
|
||||
return profilePic ? profilePic.eurl : undefined;
|
||||
return await this.client.getProfilePicUrl(this.id._serialized);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user