#how to send gif and videos through this api?

5 messages ยท Page 1 of 1 (latest)

brisk wren
#

how to send gifs

distant quartz
#
const { Client, Location, List, Buttons, LocalAuth, MessageMedia } = require('whatsapp-web.js');
const imagem = await MessageMedia.fromFilePath('teste.gif');
await client.sendMessage(number, imagem);
const video = await MessageMedia.fromFilePath('teste.mp4');
await client.sendMessage(number, video);
brisk wren
#

thanks

#

ill try

proud topaz
#

This is the approach that I follow , it works for text,image,audio and docx but not for video
app.get(EventEmitterService).on('send_msg',async (event) => {
console.log('Send msg event:', event);
const chatFound=await client.getChatById(event.data.id);
console.log("๐Ÿš€ ~ file: main.ts:249 ~ app.get ~ chatFound:", chatFound)
// if(chatFound.isGroup){
// const checkMsgSendGroup=await chatFound.sendMessage(event.data.message);
// console.log("๐Ÿš€ ~ file: main.ts:251 ~ app.get ~ checkMsgSendGroup:", checkMsgSendGroup)
// }else{
try{
const data=event.data;
if(event.data.media){
const mimeType=data.mimeType;
const media=data.media;
const name=data.name;
const caption=data.caption || undefined;

    var mediaMsg =  new MessageMedia(mimeType,media,name);
    console.log("๐Ÿš€ ~ file: main.ts:263 ~ app.get ~ mediaMsg:", mediaMsg)
    try{
      const checkmediamsg=await chatFound.sendMessage(mediaMsg, {caption:caption});
  console.log("๐Ÿš€ ~ file: main.ts:262 ~ app.get ~ checkmediamsg:", checkmediamsg)
    }catch(e){
      console.log(e);
      
    }
 
  }else{
    if(data.message){
      await chatFound.sendMessage(data.message);
     }
  }
 
}catch(error){
  pusher.trigger("chat","error-msg",error);
}

// }
});

this is the error I am getting

Error: Evaluation failed: N
at ExecutionContext._evaluateInternal (C:\sample\waba_whatsapp_chat\node_modules\puppeteer\src\common\ExecutionContext.ts:273:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at ExecutionContext.evaluate (C:\sample\waba_whatsapp_chat\node_modules\puppeteer\src\common\ExecutionContext.ts:140:12)
at Client.sendMessage (C:\sample\waba_whatsapp_chat\node_modules\whatsapp-web.js\src\Client.js:795:28)
at EventEmitter.<anonymous> (C:\sample\waba_whatsapp_chat\src\main.ts:265:31)