grammyjs/conversations

How to set custom context properties when using conversations?

waptik opened this issue · 2 comments

Hi. I have a bot where i'm using a custom context with additional properties that i have set to make them available in the whole bot.
I originally posted the issue on the official chat group https://t.me/grammyjs/97968, but here i am with a minimal repro.
If you follow the chat link, you'll get to discover the whole conversation linked to it.
In short, i'm not not able to set the properties when using the conversations plugin.

I might not be doing things right, so i kinda need help with it.

The repo is at https://github.com/waptik/grammy-conversations-demo

I don't feel like going through a whole project with dozens of files, a complete database setup and way too many nested folders for this.

Can you explain why you even need to set any properties on the context object? Is that just to pass in arguments into the conversation? Setting custom properties is useful to pass values from one traditional middleware handler to the next, but if you're using conversations, this suddenly seems like a very odd problem to solve. Perhaps this is an https://xyproblem.info?

Sorry, for leaving this opened for this long. Actually, the issue has been solved by using an alternative method where i created a helper function and just called it anywhere it's needed.

So i wanted to have properties attached to the context to make it easier for me to have access to the database client (eg. ctx.db) and user info from db(eg. ctx.user) as the bot relies heavily on a database. So i thought it'd make it easier for me to use in conversations, commands, menus but yeah, it was just wishful thinking.

All solved now. Thanks for replying tho.