node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

manage user session, ie wizard

Open Evgenyx82 opened this issue 4 years ago • 1 comments

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:

  1. bot shows select "enter name" or "enter number", for example user push "enter name" button
  2. user type his name and send as usual message
  3. then bot shows select "option1" or "option2", "back button"
  4. and so on...

Evgenyx82 avatar Jul 15 '21 11:07 Evgenyx82

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)

kamikazechaser avatar Aug 21 '21 07:08 kamikazechaser