Closed Peterculazh closed 6 months ago
ctx.conversation
generally isn't available inside conversations, even though it may sometimes accidentally. Sadly, there is no way to fix this such that it can work reliably in all cases. The solution to this problem is to work on #53 instead.
ctx.conversation
generally isn't available inside conversations, even though it may sometimes accidentally. Sadly, there is no way to fix this such that it can work reliably in all cases. The solution to this problem is to work on #53 instead.
So currently only way to exit conversation is throw error and catch? Is conversation deletes properly from array of conversations in case of throwing error inside otherwise
?
Works fine in such way, but now I'm worrying about not storing a N-amount of conversations because of throwing error :sweat_smile:
try {
await conversation.waitForCallbackQuery([Language.en, Language.ua], {
otherwise: async (ctx) => {
// await ctx.conversation.exit('change_language');
await ctx.reply(localization.t('changeLanguage.pressedWrongDuringChanging'));
throw new Error(`trying to exit conversation`);
},
});
} catch (error) {
// catches error and returns
console.log(error);
return;
}
PS. I figured out that with return at catch it actually leaving conversation?
I'd just handle all updates and avoid running into otherwise
when I want to leave a conversation, but yes, from within otherwise
, there currently isn't another way. The APIs are definitely still lacking there.
now I'm worrying about not storing a N-amount of conversations because of throwing error
I don't understand this part
with return at catch it actually leaving conversation?
Yes
now I'm worrying about not storing a N-amount of conversations because of throwing error
I don't understand this part
Meant that in case of not properly leaving conversations and not clean them, they stays in memory forever and eventually will occur memory out.
I'd just handle all updates and avoid running into otherwise when I want to leave a conversation, but yes, from within otherwise, there currently isn't another way
Got it, thanks, will think about not using otherwise.
Feel free close that issue
now I'm worrying about not storing a N-amount of conversations because of throwing error
I don't understand this part
Meant that in case of not properly leaving conversations and not clean them, they stays in memory forever and eventually will occur memory out.
Conversations are stored in a database, they only consume ram while they're being executed or if you store your sessions in memory
I'd just handle all updates and avoid running into otherwise when I want to leave a conversation, but yes, from within otherwise, there currently isn't another way
Got it, thanks, will think about not using otherwise.
Feel free close that issue
Alright
Hello, I'm getting crash during exiting conversation
Reproduction: firstly I tried to use
drop
parameter to exit conversation, but seems it's not related to actually exiting and I decided to usectx.conversation.exit
to actually exit conversation. There a example ofotherwise
callback:I've looked up in source code and that occurs because of
session.conversation[id].length === 0
wheresession.conversation
isundefined
Fix looks just like that
session?.conversation && session.conversation[id].length === 0
, but I'm not figure out how I would can run tests for checking up is change broke something or not?