hellostealth / stealth

An open source Ruby framework for text and voice chatbots. 🤖

Home Page:https://hellostealth.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stealth route system

luizcarvalho opened this issue · comments

A more power route system.
I not found a way to build several routes to evaluate content message and forward to specific flow/state. Like a Rails Routes or a Lita Chat Routes. Maybe this be a good idea to avoid many if's in Controllers.

I Would like a config file to put my routes using regex
When message coming, try match with any route described in this file, and, if match, step_to the specific flow/state.

Same like

Stealth.routes.draw do
  match /^hello/, step_to: flow: 'hello', state: 'say_hello'
  match /^bye/, step_to: flow: 'goodbye', state: 'say_goodbye'
end

Hi @luizcarvalho,

Can you elaborate a little on your use-case? We've built a few bots now and haven't needed a full blown routes system. For the most part, all of our route methods in BotController look like this:

def route
    if current_message.payload.present?
      handle_payloads
      current_message.payload = nil
      return
    end

    if current_session.present?
      step_to session: current_session
    else
      step_to flow: 'hello', state: 'say_hello'
    end
  end

handle_payloads is a method with a case statement to handle Facebook button payloads.

Nicee, this is works to most of my problems haha, thanks. I not found this in docs.
But, when user send a random text message? I'll need use NLP?

I should add an example of handle_payloads to the stealth-facebook gem. It's pretty Facebook specific though as other message platforms often don't have the same concept of a "payload". I think it'll be helpful for everyone, though.

Basically that route method comes with BotController and is required to be there. By default, users are sent to hello->say_hello. If a user has progressed beyond the hello flow, then they get sent to the last position in their session. It could be any other flow and state you have specified.

So when a user types a random string into your bot, it wouldn't be the responsibility of the route method to determine what to do with it, it would be whatever state the user is in that may be expecting a response. In most cases you should try to design the response to be simple. So for a Facebook bot, we recommend utilizing quick replies and buttons. But certainly you may have open ended user input that needs validation or NLP. For NLP, we currently have integrated AWS Comprehend (https://github.com/hellostealth/stealth-aws-comprehend) but you could also add in support for others.

I recommend checking our docs on sessions: https://hellostealth.org/docs/#sessions. Hopefully we'll have screencasts available soon that will make this all more clear. 👍

I understood. I'll wait for a demonstration of use to be more clear how your use this.

Thank very much my friend. :D