WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
3.68k stars 1.24k forks source link

[BUG] Erro to send media message #149

Closed rafaelvmedeiros closed 1 year ago

rafaelvmedeiros commented 1 year ago

hi everyone. does anyone getting this error? I'm using "@whiskeysockets/baileys": "^6.2.1" and i'm getting error when i try to send a image only.

sharecontacts and text works fine. but when i try to send an image, i got this error.

const sentMessage = await wbot.sendMessage("12345@s.whatsapp.net", { image: fs.readFileSync('C:\Projects\backend\public\img-2.jpg', caption: "img-2.jpg" } );

image

{ data: null, isBoom: true, isServer: true, output: { statusCode: 500, payload: { statusCode: 500, error: "Internal Server Error", message: "An internal server error occurred", }, headers: { }, },

Stack Error

'Media upload failed on all hosts'

'Error: Media upload failed on all hosts\n at Object.upload (C:\Projects\optinchat-old\backend\node_modules\@whiskeysockets\baileys\lib\Utils\messages-media.js:539:19)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at C:\Projects\optinchat-old\backend\node_modules\@whiskeysockets\baileys\lib\Utils\messages.js:110:28\n at async Promise.all (index 0)\n at prepareWAMessageMedia (C:\Projects\optinchat-old\backend\node_modules\@whiskeysockets\….js:472:59)\n at Object.sendMessage (C:\Projects\optinchat-old\backend\node_modules\@whiskeysockets\baileys\lib\Socket\messages-send.js:606:33)\n at SendWhatsAppMedia (C:\Projects\optinchat-old\backend\src\services\WbotServices\SendWhatsAppMedia.ts:173:25)\n at C:\Projects\optinchat-old\backend\src\controllers\MessageController.ts:86:11\n at async Promise.all (index 0)\n at store (C:\Projects\optinchat-old\backend\src\controllers\MessageController.ts:84:7)'

image

image

image

lukasportal commented 1 year ago

same here:

Cannot read properties of undefined (reading 'destroy')
TypeError: Cannot read properties of undefined (reading 'destroy')
    at encryptedStream (/.../node_modules/@adiwajshing/baileys/lib/Utils/messages-media.js:346:16)
    at async prepareWAMessageMedia (/.../node_modules/@adiwajshing/baileys/lib/Utils/messages.js:101:109)
    at async generateWAMessageContent (/.../node_modules/@adiwajshing/baileys/lib/Utils/messages.js:327:13)
    at async generateWAMessage (/.../node_modules/@adiwajshing/baileys/lib/Utils/messages.js:472:59)
    at async Object.sendMessage (/.../node_modules/@adiwajshing/baileys/lib/Socket/messages-send.js:606:33)
Luxemburgo commented 1 year ago

WhatsApp service isn't working properly today for file uploads, nothing to do with Baileys. Relax

rafaelvmedeiros commented 1 year ago

WhatsApp service isn't working properly today for file uploads, nothing to do with Baileys. Relax

I've been having this problem for three days already. So.. this is from whatsapp service?

lukasportal commented 1 year ago

Not sure though If you send an image using a Readable stream instead of an URL, it works so you can indeed upload an image to whatsapp if you pass a Readable stream to Baileys instead of a url

rafaelvmedeiros commented 1 year ago

Not sure though If you send an image using a Readable stream instead of an URL, it works so you can indeed upload an image to whatsapp if you pass a Readable stream to Baileys instead of a url

I'm not using URL. I´m using buffer.

options = {
    image: fs.readFileSync(`${publicFolder}/${media.filename}`),
    caption: body,
  };

I´m seeing in the interface I´ll try use Redable instead Buffer.

image

lukasportal commented 1 year ago

not saying this is good or the way to go.. i do think sending a URL is so much better just saying that this may not be due to whatsapp being down today

rafaelvmedeiros commented 1 year ago

not saying this is good or the way to go.. i do think sending a URL is so much better just saying that this may not be due to whatsapp being down today

I'll try. But i think it´s a problem in url media from what´s service. Because the error is about 'certificate'.

image

I've changed the axios parameters to ignore invalid certificate, but it not works. I'm getting this error in my environment (local) and production machine.

rafaelvmedeiros commented 1 year ago

messages-media.js

When Baileys try to send media data and get any error.. it try to request using another links, but anyone are works.

https://media.fgig22-1.fna.whatsapp.net/mms/image/LiV9gwf77Cc07ViNV77_lsEf0Xc-N-BsbxIwjpgFTSM?auth=AWT0NDbF11F7nTEqUfEwaYPz1iI05i5oFxpZzMH0rlLG8WeO4I3Yn4nMiH8&token=LiV9gwf77Cc07ViNV77_lsEf0Xc-N-BsbxIwjpgFTSM

https://media-gig4-1.cdn.whatsapp.net/mms/image/_Nqg2DwtxPqsCzrSKAbjG7mBxxpxIkzBaf54hmc6RpQ?auth=AWRyaSZJMzLIMsfE-gpNXFLbYz_4vLY-gOlOgoAZmglo23ONY39Sgj2UPl8&token=_Nqg2DwtxPqsCzrSKAbjG7mBxxpxIkzBaf54hmc6RpQ

https://mmg.whatsapp.net/mms/image/LiV9gwf77Cc07ViNV77_lsEf0Xc-N-BsbxIwjpgFTSM?auth=AWT0NDbF11F7nTEqUfEwaYPz1iI05i5oFxpZzMH0rlLG8WeO4I3Yn4nMiH8&token=LiV9gwf77Cc07ViNV77_lsEf0Xc-N-BsbxIwjpgFTSM

image

rafaelvmedeiros commented 1 year ago

I generated a link using what'sapp web If i try it in browser works well. https://media.fgig22-1.fna.whatsapp.net/mms/image/9vQ9LJcArnC56c9X_1qTk6dRY5GGrJKotol5DgTUleQ=?auth=Ac0IB0T44fwyM-c1EK6cQpFqP50Kkxu7qguzQyeQk0gv3Q&token=9vQ9LJcArnC56c9X_1qTk6dRY5GGrJKotol5DgTUleQ%3D&resume=1&media_id=579306653185760

I've setted this link in code, But i got the same error.

Anyone knows why i'm getting this error? Should i running node with https directly? Should i make the request directly in frontend?

image

image

I'm trying to ignore it in the code, but without success.

image

rafaelvmedeiros commented 1 year ago

I fix that. If anyone has this issue. I solved this way:

I downloaded the whatsapp crt file from whatsapp web.

image

const certsPath = resolve(__dirname, "..", "..", "certs"); const cert = readFileSync(${certsPath}/whatsapp.crt);

and i loaded it there:

image

Now all is working fine.