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
  • Accessible Instances and methods
  • @user
  • @message
  • @reply
  • Methods

Was this helpful?

Conversation Class

PreviousNLP ConfigurationNextContexts

Last updated 2 years ago

Was this helpful?

The Conversation class is located at app/conversation.rb file.

Every message that arrives and every reply sent can be handled and accessed via callbacks defined here and all the should inherit this class.

For those who are familiar with Ruby on Rails, this class is the equivalent to ApplicationController.

class Conversation < Kogno::Context

  before_blocks :do_something_before_blocks
  after_blocks :do_something_after_blocks

  def do_something_before_blocks
    # This will be called before the blocks method in the current context will be executed
  end

  def do_something_after_blocks
    # This will be called after the blocks method in the current context will be executed
  end

end
Callback
Description

before_blocks

after_blocks

before_exit

Accessible Instances and methods

@user

It is an instance of the User model (ActiveRecord::Base) that corresponds to the user who sent the incoming message.

Usage

class Conversation < Kogno::Context

  before_blocks :log_user_platform

  def log_user_platform
    logger.info "The user's platform is #{@user.platform}"
  end

end

@message

It is the instance of the user's incoming message.

Usage

  • To see the message content: @message.text

  • Check if the message is empty: @message.empty?

See the full list of methods here.

@reply

In Kogno, we try to unify almost all reply types for all supported platforms, so that a single code can be written for all of them.

Usage

class Conversation < Kogno::Context

  after_blocks :send_a_final_message

  def send_a_final_message
    @reply.text "I'll respond this mesage all the time."
  end


end

Methods

This callback will be executed before the method from a Context class is called.

This callback will be executed after the method from a Context class is called.

This callback will be executed before the conversation context is changed. Specifically in the call of methods .

In this callback, the method can be implemented, to prevent the conversation context finally changes or exit.

These instances and methods are accessible from the Conversation class and also from any defined in a project.

Catch a button click event: @message.postback_payload and if includes parameters @message.postback_params. Read more about .

It is an instance of the Kogno::Notification class, which contains a wide variety of reply messages like text, button, url, carousel, etc. Full list .

For more information and examples, check the .

Also methods like , and .

Contexts
Context class
postbacks
Replies section
blocks()
blocks()
change_to() or context_exit()
change_to()
delegate_to()
here
halt()
halt()