Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
721 stars 143 forks source link

How to stop conversation in form? #42

Closed mort3za closed 8 years ago

mort3za commented 8 years ago

Assume we have a form that has a special field with a validation that user don't understands how to fill it and wants to go back and see the tutorial. How we can listen for /stop in middle of questioning form fields?

danieltorrer commented 8 years ago

@mort3za I'm also having the same problem, did you find any fix?

mort3za commented 8 years ago

@danieltorrer Not yet :(

mort3za commented 8 years ago

@danieltorrer Found solution. Inside validator:

if (input['text'] && input['text'] == '/stop') {
  $.sendMessage("Operation stopped. You can /start again.")
  return // return without running callback
}
if (input['text'] && input['text'].length >= 6) {
  callback(true)
  return
}
callback(false)

And just added /stop to list of commands in BotFather.

danieltorrer commented 8 years ago

@mort3za Awesome, I was thinking in some kind of middleware before every route but I couldn't dig into the code