Skip to content

show how to send media from Buffer #86

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/guide/creating-your-bot/handling-attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ client.on('message', async (msg) => {
});
```

### Sending Files from a Buffer

You can also manipulate data from other formats and create a new MessageMedia object:

```javascript
const { MessageMedia } = require('whatsapp-web.js');

client.on('message', async (msg) => {
if (msg.body === '!send-media') {
// Create an buffer object
const someBuffer = Buffer.from(...);

const media = new MessageMedia('mime/type', someBuffer.toString("base64"));
await client.sendMessage(msg.from, media);
}
});
```

### Caveat for Sending Videos and GIFs

Whatsapp-web.js uses [Puppeteer](https://github.com/Puppeteer/Puppeteer), which comes bundled with the Chromium browser, an open source version of the popular Google Chrome browser. Since AAC and H.264 are licensed formats, they are not supported by Chromium. More info on this can be found on the [Puppeteer documentation](https://developer.chrome.com/docs/puppeteer/faq#what_features_does_puppeteer_not_support).
Expand All @@ -103,4 +121,4 @@ The `executablePath` value will depend on your OS and install location for Chrom

* **macOS:** `/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`
* **Windows**: `C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe`
* **Linux:** `/usr/bin/google-chrome-stable`
* **Linux:** `/usr/bin/google-chrome-stable`