pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.05k stars 3.58k forks source link

No media sent #529

Closed Seramak closed 3 years ago

Seramak commented 3 years ago

Hello. Can't send document

I'm trying to send an attachment on demand, but I get an error in response.

const fs = require('fs');
const { Client } = require('whatsapp-web.js');
const { MessageMedia } = require('whatsapp-web.js');
...
client.on('message', message => {
    msg = message.body
        console.log('WHATSAPP: ' + msg);
    if (msg === 'download test.txt'){
        const media = MessageMedia.fromFilePath('/home/mak/test.txt');
        client.sendMessage(media);
    }
});

console output:

WHATSAPP: download test.txt
(node:4080) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: e.match is not a function
    at new u (https://web.whatsapp.com/app.11f3f20018994f92d6d9.js:1:1524268)
    at Object.o [as createWid] (https://web.whatsapp.com/app.11f3f20018994f92d6d9.js:1:870893)
    at __puppeteer_evaluation_script__:2:53
    at ExecutionContext._evaluateInternal (/opt/whatsappbot/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:217:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4080) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4080) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Thanks

Seramak commented 3 years ago

What am I doing wrong?

erick-gomes commented 3 years ago

Example: client.sendMessage(notification.id.remote, media)

Seramak commented 3 years ago

Example: client.sendMessage(notification.id.remote, media)

Yes thank you. It works. I was confused by the line from the example in the documentation :)))

pedroslopez commented 3 years ago

Example: client.sendMessage(notification.id.remote, media)

Yes thank you. It works. I was confused by the line from the example in the documentation :)))

Just FYI the docs state chat.sendMessage, not client.sendMessage, and you can get the chat if you wanted to by calling const chat = await message.getChat().

devAdityaa commented 1 year ago

Example: client.sendMessage(notification.id.remote, media)

Yes thank you. It works. I was confused by the line from the example in the documentation :)))

Example: client.sendMessage(notification.id.remote, media)

It's showing me notification is not defined ಥ_ಥ