yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.45k stars 1.53k forks source link

How to use getFileStream #940

Closed Arjun-M closed 2 years ago

Arjun-M commented 2 years ago

let code = 111 let newFile = JSON.parse( Bot.getFileStream(body.message.reply_to_message.document.file_id ) ) console.log (newFile) let oldFile = JSON.parse( fs.readFileSync( 'server/history/'+code+'.json' , 'utf8')) let merged = { ...newFile , ...oldFile } fs.writeFileSync( 'server/history/'+code+'.json' , JSON.stringify(merged)); return Bot.sendDocument(body.message.from.id , 'server/history/'+code+'.json' , {caption : "Updated Chat History" , parse_mode: "Markdown" } , {contentType: 'application/json' , filename: data.username+".json"})

I tried using this but fails

danielperez9430 commented 2 years ago

// Let's imagine that the file id is from an image

cont fileStream = bot.getFileStream("<Id of the file>"

// Do something?

bot.sendPhoto("chat_id, fileStream)

Internally what it does is call bot.getFileLink("<Id of the file"). When it gets that URL, it does a get to download the file and returns the file stream.