Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get contact profile picture in base64 and not in URL #1542

Closed
1 task done
yonatanm opened this issue Jun 24, 2022 · 3 comments
Closed
1 task done

get contact profile picture in base64 and not in URL #1542

yonatanm opened this issue Jun 24, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@yonatanm
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

Currently, if I want a profile picture of a contact or a group, I get the URL.
for example: https://docs.wwebjs.dev/Client.html#getProfilePicUrl (similar method on the Contact class)
From what I understand, the image can be downloaded by the browser via puppeteer, so I would prefer that it is available in base64.

  • reducing traffic by avoiding downloading it on my end, especially if the browser has already done so
  • to align with the MessageMedia that exposes the image in base64.

Describe the solution you'd like.

add an a method Client.getProfileMedia() which will return Promise of { mimetype: string, data: string}

Describe an alternate solution.

No response

Additional context

No response

@yonatanm yonatanm added the enhancement New feature or request label Jun 24, 2022
@PurpShell
Copy link
Collaborator

PurpShell commented Jun 30, 2022

just fetch it using node-fetch (it is a peer dependency by puppeteer so no installation needed) (also in Node 17+, this is a built-in feature, just use the function)

  • Before node 17: const fetch = require('node-fetch')
    • typescript: import fetch from 'node-fetch'
const url = await client.getProfilePicUrl(chatId);
const res = await fetch(url);
const data = {data: (await res.arrayBuffer()).toString('base64'), mimetype: res.headers.get('Content-Type')};

@PurpShell
Copy link
Collaborator

Is there an existing issue for this?

* [x]  I have searched the existing issues

Is your feature request related to a problem? Please describe.

Currently, if I want a profile picture of a contact or a group, I get the URL. for example: https://docs.wwebjs.dev/Client.html#getProfilePicUrl (similar method on the Contact class) From what I understand, the image can be downloaded by the browser via puppeteer, so I would prefer that it is available in base64.

* reducing traffic by avoiding downloading it on my end, especially if the browser has already done so

* to align with the MessageMedia that exposes the image in base64.

Describe the solution you'd like.

add an a method Client.getProfileMedia() which will return Promise of { mimetype: string, data: string}

Describe an alternate solution.

No response

Additional context

No response

As for your concerns, the image can get quite large and you will be using resources to copy an image in pure arraybuffer to the client. And also sometimes the cached image isn't the latest, which might bring even more concern..

Thanks for your suggestion though

@SannanOfficial
Copy link

just fetch it using node-fetch (it is a peer dependency by puppeteer so no installation needed) (also in Node 17+, this is a built-in feature, just use the function)

  • Before node 17: const fetch = require('node-fetch')

    • typescript: import fetch from 'node-fetch'
const url = await client.getProfilePicUrl(chatId);
const res = await fetch(url);
const data = {data: (await res.arrayBuffer()).toString('base64'), mimetype: res.headers.get('Content-Type')};

Just a minor correction: I am pretty sure it's supposed to be the contact's WhatsApp ID and not the chat ID, according to the docs and what I've tried. But please do let me know if I am wrong.

https://docs.wwebjs.dev/Client.html#getProfilePicUrl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants