From e1eb461cbbbb4767cf44d5c74559e21a1a58ada6 Mon Sep 17 00:00:00 2001 From: Nur Muhammad Date: Fri, 1 Jul 2022 09:41:02 +0800 Subject: [PATCH] Commenting auto download message media files script --- app.js | 60 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/app.js b/app.js index c2d291b..fa86483 100644 --- a/app.js +++ b/app.js @@ -70,42 +70,44 @@ client.on('message', msg => { }); } + // NOTE! + // UNCOMMENT THE SCRIPT BELOW IF YOU WANT TO SAVE THE MESSAGE MEDIA FILES // Downloading media - if (msg.hasMedia) { - msg.downloadMedia().then(media => { - // To better understanding - // Please look at the console what data we get - console.log(media); + // if (msg.hasMedia) { + // msg.downloadMedia().then(media => { + // // To better understanding + // // Please look at the console what data we get + // console.log(media); - if (media) { - // The folder to store: change as you want! - // Create if not exists - const mediaPath = './downloaded-media/'; + // if (media) { + // // The folder to store: change as you want! + // // Create if not exists + // const mediaPath = './downloaded-media/'; - if (!fs.existsSync(mediaPath)) { - fs.mkdirSync(mediaPath); - } + // if (!fs.existsSync(mediaPath)) { + // fs.mkdirSync(mediaPath); + // } - // Get the file extension by mime-type - const extension = mime.extension(media.mimetype); + // // Get the file extension by mime-type + // const extension = mime.extension(media.mimetype); - // Filename: change as you want! - // I will use the time for this example - // Why not use media.filename? Because the value is not certain exists - const filename = new Date().getTime(); + // // Filename: change as you want! + // // I will use the time for this example + // // Why not use media.filename? Because the value is not certain exists + // const filename = new Date().getTime(); - const fullFilename = mediaPath + filename + '.' + extension; + // const fullFilename = mediaPath + filename + '.' + extension; - // Save to file - try { - fs.writeFileSync(fullFilename, media.data, { encoding: 'base64' }); - console.log('File downloaded successfully!', fullFilename); - } catch (err) { - console.log('Failed to save the file:', err); - } - } - }); - } + // // Save to file + // try { + // fs.writeFileSync(fullFilename, media.data, { encoding: 'base64' }); + // console.log('File downloaded successfully!', fullFilename); + // } catch (err) { + // console.log('Failed to save the file:', err); + // } + // } + // }); + // } }); client.initialize();