how can I send gif in whatsapp-web js

605 Views Asked by At

does anyone know a way? this is what I tried so far and the err I get:

const media = MessageMedia.fromFilePath('C:/desktop/test.gif');
try {
    client.sendMessage(message.from, media, {sendMediaAsSticker: false});
} catch(e) {
    console.log(e);
}
 throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
                  ^
Error: Evaluation failed: 

I also tried to set sendMediaAsSticker to true and I also tried sending it with webp&mp4

1

There are 1 best solutions below

0
orsagiv94 On

you can use a mp4 file and send it as a GIF, this is how -

var user_gif = MessageMedia.fromFilePath("./images/gif_name.mp4")
client.on('message', message => {
    message.reply(user_gif, undefined, {"sendVideoAsGif": true})
});

note - the third arg on the replay function is actually an object from whatsapp-web called MessageSendOptions, if you'll look into its docs here you can find the sendVideoAsGif option which allows you to do the above