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.49k stars 3.69k forks source link

Error sending videos #429

Closed mpirescarvalho closed 3 years ago

mpirescarvalho commented 3 years ago

Bug description

I'm getting this error when I try to send media messages with videos

(node:916) UnhandledPromiseRejectionWarning: Error: Evaluation failed: t
    at ExecutionContext._evaluateInternal (C:\Projetos\gartic-whatsapp-bot\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:217:19)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at ExecutionContext.evaluate (C:\Projetos\gartic-whatsapp-bot\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:106:16)
    at Client.sendMessage (C:\Projetos\gartic-whatsapp-bot\node_modules\whatsapp-web.js\src\Client.js:469:28)    
    at PassThrough.<anonymous> (C:\Projetos\gartic-whatsapp-bot\src\controllers\YoutubeController.ts:168:9)      
(node:916) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:916) [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.

Reproduction steps

My code looks like this:

const file = 'C:/absolute/path/to/file.mp4'
const media = MessageMedia.fromFilePath(file);
await msg.reply(media);

I'm using this version of the library: whatsapp-web.js": "^1.11.0

It's worth mention that I'm trying to send a 1.8mb video, so I don't think the size is the problem

mpirescarvalho commented 3 years ago

Solved. In order to send videos you have to give puppeteer the path to a separately installed Chrome browser

const client = new Client({
    puppeteer: {
        executablePath: '/path/to/Chrome',
    }
})

I think this should be in the readme.

Oladapodaniel commented 1 year ago

Solved. In order to send videos you have to give puppeteer the path to a separately installed Chrome browser

const client = new Client({
    puppeteer: {
        executablePath: '/path/to/Chrome',
    }
})

I think this should be in the readme.

Thanks for this, the path will be different from the path to Chrome in other users system depending their os, how do i get the path dynamically, rather than just hardcoding the path there?

jocabedRios commented 5 months ago

Hi! Could somebody send me, please?

I've been using wweb.js library to send text messages, pictures and some files as PDF. Some mouths ago I tested to send videos and I dind´t get any problem. Yesterday I tried to send a video, but nothing happend not even a Error message, but I didn't received the video. I hope someone can help me.

Thanks!

My code:

async function enviarArchivo(number, filepath) {
    if (!fs.existsSync(filepath)) throw new Error('El archivo no existe.');

    var media;
    extension = path.extname(filepath);
    if(extension === ".mp4"){
        const video = fs.readFileSync(filepath);

        const mimeType = mime.lookup(filepath);

        media = new MessageMedia(mimeType, video.toString('base64'), 'video.mp4');
    } else media = MessageMedia.fromFilePath(filepath);

    client.getNumberId(number).then((response) => {
        destinatario = response._serialized;
        console.log(media);

        client.sendMessage(destinatario, media).then((response) => {
            console.log('Mensaje enviado exitosamente:', response);
        }).catch((error) => {
            console.error('Error al enviar el mensaje:', error);
        });

    }).catch((error) => {
        console.error(error);
    });
}