pranavms13 / whatsapp-node-api

A Simple NodeJS API Wrapper for WhatsApp
Other
475 stars 183 forks source link

Receive audio and image #12

Closed leoteixeira2016 closed 3 years ago

leoteixeira2016 commented 4 years ago

I usually receive messages but how to treat to receive images and audios? Any idea?

oxtrue-dev commented 3 years ago

client.on('message', async msg => { if(msg.type == 'image' && msg.hasMedia) { const image = await msg.downloadMedia(); let from = msg.from.split("@", 1); var base64DataSp = image.data.split(/^data:([A-Za-z-+\/]+);base64,(.+)$/); fs.writeFile('/var/www/html/'+from+msg.timestamp+'.jpg', base64DataSp,{encoding: 'base64'}, function(err){ if(err){ console.log(image); console.log('The file has been Faild!'); }else{ console.log('The file has been saved!'); } }); } });

for image download