grammyjs/conversations

Using getFile (even ctx.api.getFile) from conversation leads to receiving the same message again and freeze

Closed this issue · 3 comments

gen4sp commented

Not sure what happens, but the structure is following

async someFunc(){
if (message.text) {
    answerTxt = message.text
  } else if (message.voice) {
// uncomment any one line and send 2 files 
// const path = await file.download() 
// const file = await ctx.api.getFile(message.voice.file_id)
// const file = await answerContext.getFile()
 }
}

conversation(c){
c.session.i=0;
do{
   c.reply('question');
   const answerContext = await conversation.waitFor('message')
   c.log('>>', answerContext.message.message_id); // this the same after sending 2nd audio and freezing
   c.external(()=> someFunc());
   c.session.i+=1;
  } while (c.session.i<5);
}
gen4sp commented

to resolve the issue I have to use new bot, and use bot.api.getFile instead of ctx.api.getFile()

you didnt await the c.reply and c.external(asyncFn)

If you run your bot on webhooks, you cannot download large files inside your middleware. This includes conversations. You need to offload large file handling to task queues which you can in turn supply from conversations. Check out https://grammy.dev/guide/deployment-types#ending-webhook-requests-in-time.