grammyjs / conversations

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

Troubles with changing locale inside of conversation #80

Open archimag opened 1 year ago

archimag commented 1 year ago

Hi!

I use redis session storage, i18n and convesation plugins. Now I am working on Settings dialogue. I want to ask from user the new locale, to change current one and to reply with using of new locale. But inside of conversation the object ctx.i18n just don't real (becasue it restored from session data) and so I cannot to call of ctx.i18n.setLocale.

How I can solve this problem? Thank you.

P.S. Regadless of this issue I want to say - very nice and useful library.

archimag commented 1 year ago

I have solved the problem but it is a hack:

ctx = (conversation as any).ctx;
ctx.session.locale = locale;
await ctx.i18n.renegotiateLocale();
KnorpelSenf commented 1 year ago

This needs to be investigated and fixed

KnorpelSenf commented 1 year ago

Before I try to investigate this, can you check if using conversation.session fixes the issue? https://grammy.dev/plugins/conversations.html#rule-iii-use-convenience-functions

/cc @dcdunkan perhaps you may an idea what causes this