I am developing telegram bot using grammy. I use two sessions in my bot: one with external storage, one with memory storage (for conversations).
bot.use(session({
profile : {
storage : require('./storage.js')
},
conversation : {}, type : 'multi'
}));
I am traking when different methods of storage was called and was suprised when I found that each time when user enters the conversation profile storage’s write method is called with no changes. I didn’t expect such behaviour and still don’t understand it. Encoding to documentation conversation should only use session provided for them (conversation session).
2
Answers
I assume you use
await conversation.wait()
for this purpose. This method creates a new context object and you have to work with it instead of the original context object.This means that instead of writing
you’ll have to use
Working with the new context object fixed my problem with values dissapearing from the context object used later on.
Not the prettiest solution, but it works!
With grammyjs conversation plugin, you should use conversation.session utility to deal with sessions objects as indicated in the documentation #rule-iii-use-convenience-functions :