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
  • template(route=String, params=Hash)
  • Usage
  • File Location
  • File Content
  • params argument
  • Arguments
  • Template reuse example

Was this helpful?

Templates

It calls a template with extension ".erb" and executes it. There may be just one or a serie of replies.

template(route=String, params=Hash)

Usage

@reply.template "main/menu", { title: "But, I can help you with this" }

File Location

bot/templates/main/menu.erb

Templates are found in sub-directories under bot/templates/ and each sub-directory within has the same name as an existing context in a given project.

For example: bot/templates/context_name/template_name.erb.

File Content

The code in the template must be written between the chars <% %>.

<%
  @reply.quick_reply(
    title,
    [
      {
        title: "Subscribe",
        payload: "profile/sign_up"
      },
      {
        title: "Follow US",
        payload: :twitter
      },
      {
        title: "Contact US",
        payload: :contact_us        
      }
    ]
  )
%>

params argument

The params argument can contain various elements which are accessed as a local variable within the template. In the example above: title.

Arguments

Name
Description

route String

Required.

The template route.

Formats:

  • "context_name/template_name"

  • "template_name" (If the template is in the same context from where this method was been called)

params Hash

Optional. Parameters that are passed to the template as local variables.

Template reuse example

In the example below, the "main/menu" template will be called in 3 different situations in the conversation:

  1. When the user sends a greeting..

  2. When the user thanks..

  3. When the app cannot understand what the user has said.

class MainContext < Conversation

  def actions

    intent :gretting do
      @reply.text "Hello!"
      @reply.template "main/menu", { title: "How can I help you?" }
    end

    intent :thanks do
      @reply.text "You're welcome!"
      @reply.template "main/menu", { title: "Is there anything else I can help you with?" }
    end

    everything_else do
      @reply.text "Sorry, but I don't understand what you said."
      @reply.template "main/menu", { title: "But, I can help you with this" }
    end

  end

end
Previouswhatsapp_templateNextModels

Last updated 2 years ago

Was this helpful?