grammyjs / conversations

Conversational interfaces for grammY.
https://grammy.dev/plugins/conversations
MIT License
44 stars 17 forks source link

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

Closed gen4sp closed 9 months ago

gen4sp commented 10 months ago

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 10 months ago

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

gomez-git commented 9 months ago

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

KnorpelSenf commented 9 months ago

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.