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)
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
params
argumentThe params argument can contain various elements which are accessed as a local variable within the template. In the example above: title
.
Arguments
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:
When the user sends a greeting..
When the user thanks..
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
Last updated
Was this helpful?