node-telegram-bot-api
node-telegram-bot-api copied to clipboard
manage user session, ie wizard
Hi there.
Which proper way to manage user session with the library? I want something like wizard with inline_keyboard, i don't know how to track in which node current user is in.
for example:
- bot shows select "enter name" or "enter number", for example user push "enter name" button
- user type his name and send as usual message
- then bot shows select "option1" or "option2", "back button"
- and so on...
You can use redis or use an in memory map:
// pseudocode
const memStore = {
userId: step (type int)
}
bot.on("message", msg => {
if (msg.user.id in memStore) {
// check step and send appropriate message or save result depending on step
// update step
return
}
// new user send welcome message
})
Alternatively you can use forfuturellc/mau (unmaintained, but can do the job)