I am using node.js telegraf module to create a telegram bot.
I am using the code below.
var picture = (context)ctx.message.photo[0].file_id;
var photo = `https://api.telegram.org/bot1234-ABCD/getFile?file_id=${picture}`;
console.log(photo.file_path);
3
Answers
You can use axios to store the images. Assuming you have the file id as
fileId
and the context asctx
. I am storing the image at the path${config.basePath}/public/images/profiles/${ctx.update.message.from.id}.jpg
How do I get the file id of the image sent for the bot
Don’t forget to install axios as
npm install axios --save
and require it asconst axios = require('axios')
N.B. Don’t publish the file links publicly as it exposes your bot token.
If you want to download the highest quality photo you can use this command for the high quality file id
let fileId = ctx.message.photo.pop().file_id;