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.41k stars 3.68k forks source link

downloadMedia PTT #546

Closed tofers closed 3 years ago

tofers commented 3 years ago

Bug description

I send a voice message and wait for it in the message_create event. But you can't get media. Voice message can be saved only when ask = 2

Reproduction steps

Steps to reproduce the behavior:

  1. I send vouce message outgong
  2. event message_create
  3. no download media ...

Expected behavior

A clear and concise description of what you expected to happen.

Relevant code

If applicable, add code snippets to help explain your problem.

Environment (please complete the following information):

WhatsApp

Library

Additional context

Add any other context about the problem here.

ptt hasMedia false

info data message in src/structures/Message.js

{ id: { fromMe: true, remote: '41798931892@c.us', id: '3A6472D073AE565C792A', _serialized: 'true_41798931892@c.us_3A6472D073AE565C792A' }, type: 'ptt', t: 1613383672, notifyName: '', from: '88888@c.us', to: '41798931892@c.us', self: 'in', ack: 1, invis: false, isNewMsg: true, star: false, recvFresh: true, mimetype: 'audio/ogg; codecs=opus', duration: '1', filehash: 'FARcf4iQlwDw3TfK24d2rpvIEZWm1UrN2qhkBbLMWq8=', size: 4227, streamingSidecar: {}, mediaKey: 'Jn53OInLjKweqMM7Ps6UhzscztgQwVL2BL6FWVg+DNQ=', mediaKeyTimestamp: 1613383672, isFromTemplate: false, mentionedJidList: [], isVcardOverMmsDocument: false, isForwarded: false, labels: [], isDynamicReplyButtonsMsg: false, isStatusV3: false, links: [] }

info msg in lib { mediaKey: 'Jn53OInLjKweqMM7Ps6UhzscztgQwVL2BL6FWVg+DNQ=', id: { fromMe: true, remote: '41798931892@c.us', id: '3A6472D073AE565C792A', _serialized: 'true_41798931892@c.us_3A6472D073AE565C792A' }, ack: 0, hasMedia: false, body: '', type: 'ptt', timestamp: 1613383672, from: '888888@c.us', to: '41798931892@c.us', author: undefined, isForwarded: false, isStatus: false, isStarred: false, broadcast: undefined, fromMe: true, hasQuotedMsg: false, location: undefined, vCards: [], mentionedIds: [], links: [] }

How to get voicemails other than downloadMedia method. Since it doesn't work

tofers commented 3 years ago

I noticed that the link deprecatedMms3Url is available with ack = 2 or 1

{ id: { fromMe: true, remote: '41798931892@c.us', id: '3A6472D073AE565C792A', _serialized: 'true_41798931892@c.us_3A6472D073AE565C792A' }, type: 'ptt', t: 1613383672, notifyName: '', from: '88888@c.us', to: '41798931892@c.us', self: 'in', ack: 2, invis: false, isNewMsg: true, star: false, recvFresh: true, deprecatedMms3Url: 'https://mmg.whatsapp.net/d/f/AugXTetG5G_0j507IAJuluAKcuUqP_qH0EOGcM_K_skp.enc', directPath: '/v/t62.7117-24/40792717_646706276041048_4589602888924033329_n.enc?oh=5c9dcdaff3e6a14fcb9c755a3afa732d&oe=6052E789', mimetype: 'audio/ogg; codecs=opus', duration: '1', filehash: 'PtS5MhTSm5mosd4k9yPIL0nrFUBAjagKVw2cEt2C55k=', encFilehash: 'frvh7yt9KqW5BLx/g/rLSSpRT3YEhJcWupS2vT2yF9M=', size: 4227, streamingSidecar: {}, mediaKey: 'Jn53OInLjKweqMM7Ps6UhzscztgQwVL2BL6FWVg+DNQ=', mediaKeyTimestamp: 1613383669, isFromTemplate: false, mentionedJidList: [], isVcardOverMmsDocument: false, isForwarded: false, labels: [], ephemeralStartTimestamp: 1613383673, isDynamicReplyButtonsMsg: false, isStatusV3: false, links: [] }

pedroslopez commented 3 years ago

When you are uploading media, getting the message before media has been completely uploaded will result in hasMedia: false and will not allow you to download it again. In these cases, you could listen for the media_uploaded event, which will be called once everything has finished uploading.

https://pedroslopez.me/whatsapp-web.js/Client.html#event:media_uploaded