Skip to content
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

feat: make isViewOnce messages downloadable #3338

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

alechkos
Copy link
Collaborator

@alechkos alechkos commented Oct 18, 2024

PR Details

Make isViewOnce messages downloadable.

Description

The PR makes isViewOnce messages (image, video and ptt) downloadable.
Works for messages sent from both the web client and mobile.

Related Issue

closes #3275

How Has This Been Tested

const fs = require('fs');

// client initialization...

client.on('message', async (msg) => {
    if (msg._data.isViewOnce) {
        const media = await msg.downloadMedia();

        fs.writeFileSync(
            `${msg.type === 'image'
                ? `./image-${Date.now()}.png`
                : msg.type === 'video'
                    ? `./video-${Date.now()}.mp4`
                    : `./ptt-${Date.now()}.mp3`}`,
            Buffer.from(media.data, 'base64')
        );
    }
}

You can try the feature by running one of the following commands:

  • NPM
npm install github:alechkos/whatsapp-web.js#downloadable-view-once-msgs
  • YARN
yarn add github:alechkos/whatsapp-web.js#downloadable-view-once-msgs

Types of changes

  • Dependency change
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (index.d.ts).
  • I have updated the usage example accordingly (example.js)

@rafaelsupport
Copy link

it worked for me
thx a lot

@alexduca
Copy link

alexduca commented Oct 19, 2024

Thank you so much for this!
But i have some problems with video.

This is my code:

...
var path_contact = 'path/to/folder/';
const media = await message.downloadMedia();
const mediaBufferData = Buffer.from(media.data, 'base64');
		    
if(message.type === 'image'){
    var mediaPatchName = 'image-' + Date.now() + '.png';
    var mediaPath = path_contact+'/'+mediaPatchName;
} else if(message.type === 'video'){
    var mediaPatchName = 'video-' + Date.now() + '.mp4';
    var mediaPath = path_contact+'/'+mediaPatchName;
} else if(message.type === 'ptt'){
    var mediaPatchName = 'ptt-' + Date.now() + '.mp3';
    var mediaPath = path_contact+'/'+mediaPatchName;
}
fs.writeFileSync(mediaPath,mediaBufferData);
...

This save an .mp4 file but I cant open it, and if I open it i see nothing!

@alechkos
Copy link
Collaborator Author

@alexduca

This PR only makes view-once messages downloadable (like regular media messages), as they were before the WhatsApp patch.
If you have problems downloading the files, you'll need to figure out how to download them yourself.

I also tested all file types (images .png, videos .mp4 and audio (ptt) .mp3), and they all opened successfully. Maybe you have to check the sent file itself.

@adjafio

This comment was marked as off-topic.

@BenyFilho

This comment was marked as off-topic.

@opssemnik
Copy link

opssemnik commented Nov 23, 2024

I can confirm it works until 2.3000.1017322261-alpha
Afterwards videos stop working as the above commented mentioned

Reverting to older wweb version works.

On this version, the video media does properly appear but fails to be decrypted, altough i am able to download the encrypted media just fine

The weird thing is photos still work, and the properties of the message are the same (aside from the different media types etc) - meaning - it does not miss any fields. , it just does not decrypt the media , so downloadMedia fails. The media body is sill a valid encrypted media url

Reverting to older wweb version fixes the videos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ViewOnce not downloading
7 participants