Kogno
  • Introduction
  • Getting Started
    • Configuration
    • Starting the Server
    • Messenger Configuration
    • Telegram Configuration
    • WhatsApp Configuration
    • NLP Configuration
  • Conversation Class
  • Contexts
    • Blocks
      • before_anything
      • postback
      • deep_link
      • command
      • any_attachment
      • regular_expression
      • keyword
      • any_number
      • any_text
      • intent
      • entity
      • membership
      • recurring_notification
      • everything_else
      • after_all
    • Sub Contexts
    • Routing
    • Sequences
    • Conversational Forms
  • Replies / Notifications
    • text
    • button
    • quick_reply
    • raw
    • list
    • carousel
    • url
    • typing
    • image
    • video
    • html
    • markdown
    • contact
    • location
    • recurring_notification_request
    • messenger_generic_template
    • whatsapp_template
  • Templates
  • Models
    • User model
  • Scheduled Messages
  • Telegram Inline Query
  • Command Line
  • Global Methods
  • Internationalization
Powered by GitBook
On this page
  • Postback
  • Examples
  • Usage
  • Intent
  • Intent creation example in Wit.ai
  • Usage
  • Commands (Telegram)
  • Usage
  • Deep Links

Was this helpful?

  1. Contexts

Routing

Route an incoming message or event to a specific context of the conversation.

PreviousSub ContextsNextSequences

Last updated 2 years ago

Was this helpful?

It's a very useful feature when it comes to decentralizing the handling of incoming messages or events and thus to achieving a more distributed code.

Postback

A payload can contain a path to a context, in addition to the information that the payload normally carries.

Examples

Route only

"context_name/payload"

With params

set_params("context_name/payload", {p1: "value1", p2: "value2"})

Usage

class MainContext < Conversation

  def blocks
  
    intent "greeting" do
    
      @rsp.quick_reply(
        "Would you like to sign up?",
        [
          {
            title: "Create an Account",
            payload: "profile/sign_up"
          }
        ]
      )      
      
    end
    
  end
  
end

The click event on "Create an Account" button will be handled by the ProfileContext which will receive the payload without the context path information.

class ProfileContext < Conversation

  def blocks
  
    postback "sign_up" do 
    
      @reply.text "To create a new account please click in the button bellow."
      @reply.url(
        {
          title: "Create a new User",
          url: "https://kogno.io/sign_up"
        }
      )
      
    end
    
  end
  
end

Intent

In order to implement this type of routing. In the NLP engine, just create an intent whose name starts with the name of an existing context in the project, followed by an underscore and the intent's own information. For instance: profile_sign_up , where profile is the context and sign_up is the intent.

Intent creation example in Wit.ai

Usage

The profile_sign_up intent will be handled by the ProfileContext and this will be able to capture the "sign_up" intent, without path information.

class ProfileContext < Conversation

  def blocks
  
    intent "sign_up" do 
    
      @reply.text "To create a new account please click in the button bellow."
      @reply.url(
        {
          title: "Create a new User",
          url: "https://kogno.io/sign_up"
        }
      )
      
    end
    
  end
  
end

Commands (Telegram)

config.routes.commands = {
  :start => :main,
  :sign_up => :profile
}

Usage

class ProfileContext < Conversation

  def blocks
  
    command "sign_up" do 
    
      @reply.text "To create a new account please click in the button bellow."
      @reply.url(
        {
          title: "Create a new User",
          url: "https://kogno.io/sign_up"
        }
      )
      
    end
    
  end
  
end

Deep Links

Messenger Example

Telegram Example

In both examples, the click events will be be handled by ProfileContext and param value will be "sign_up", without path information

class ProfileContext < Conversation

  def blocks

    deep_link do |value|
    
      if value == "sign_up"
        @reply.text "To create a new account please click in the button bellow."
        @reply.url(
          {
            title: "Create a new User",
            url: "https://kogno.io/sign_up"
          }
        )    
      end  
      
    end

  end
  
end

In order to routing , just edit the config.routes.commands field in , adding a line with the format :command => :context_name for each command that we want to route.

Commands that have not been configured will be handled by the .

A click event on a can contain a path to a context, if the value of the params: ref (Messenger) or start (Telegram), starts with the name of an existing context in a given project.

postback
Telegram commands
config/platforms/telegram.rb
deep link
https://m.me/kogno.io/ref=profile_sign_up
https://t.me/KognoBot?start=profile_sign_up
profile_sign_up intent creation in Wit.ai
profile_sign_up intent training.
default context