I just want to download images received by my telegram bot with nodejs but I dont know witch method to use. I’m using node-telegram-bot-api
and I tried this code :
bot.on('message', (msg) => {
const img = bot.getFileLink(msg.photo[0].file_id);
console.log(img);
});
That’s the result:
Promise [Object] {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined,
_cancellationParent:
Promise [Object] {
_bitField: 1,
_fulfillmentHandler0: [Function],
_rejectionHandler0: undefined,
_promise0: [Circular],
_receiver0: undefined,
_cancellationParent:
Promise [Object] {
_bitField: 1,
_fulfillmentHandler0: undefined,
_rejectionHandler0: [Function],
_promise0: [Circular],
_receiver0: undefined,
_cancellationParent: [Promise],
_branchesRemainingToCancel: 1 },
_branchesRemainingToCancel: 1 } }
4
Answers
https://github.com/mast/telegram-bot-api/blob/master/lib/telegram-bot.js#L1407
There’re three steps: An api request to get the "file directory" on Telegram. Use that "file directory" to create the "download URL". Use "request" module to download the file.
Links that may help: https://core.telegram.org/bots/api#file and https://core.telegram.org/bots/api#getfile
For
node-telegram-bot-api
should be :Sample response :
or you can get download link by calling
getFileLink
:Result will be a string like :
or you can get download file using streams :
so your file will be saved to
myData.bin
file