Skip to content

Base bot

Your bot already comes with some basic Skills. You can enable or disable these from the Skills menu.

The following constants are used to provide the data for standard behaviors:

@menu    [@try_me]

The following dialogs are defined in the base package. You can invoke these from your own script:

invoke intro

By defining a dialog with the same name in your own script you can overwrite the base behavior. For instance:

dialog main do
  invoke intro
end

dialog hello do
  say "Howdy"
end

All default files are multilingual hence strings are wrapped in a translation function _(...)

bsqd/defaults/defaults:

intro

dialog that introduces the bot by saying its name (hello) and stating its purpose

dialog intro do
  branch do
    user.first_name -> say _"Hi #{user.first_name}, I'm #{bot.title}!"
    true            -> say _"Hi, I'm #{bot.title}!"
  end
  invoke purpose
  if !user.first_name and @name_required do
    invoke ask_name
  end
end

When setting @name_required to true in your code intro will also ask for the users name

hello

says 'hello' or when invoked again 'hello again'

dialog hello do
  once do
    say random([_("Hi!"), _("Hello"), _("Hi there")])
    say random([_("Hi again!"), _("Hello, helloโ€ฆ")])
  after
    say random([_("I believe we said hi already ๐Ÿ˜‰"), _("Yes, hello again!")])
  end
end

purpose

states the purpose declared on the bot tile

dialog purpose do
  say _"My purpose is #{bot.purpose || 'yet to be determined'}"
end

thanks

says 'thanks' or 'thanks again' when invoked again

dialog thanks do
  random do
    say _"You're welcome ๐Ÿ˜Š"
    say _"No problem ๐Ÿ‘"
    say _"Sure ๐Ÿ˜"
  end
end

confirm

Confirm acknowledge users input

dialog confirm when first(dialog.history -- [nil]) == "menu" do
  random do
    say _"I am here for you..."
    say _"Tell me..."
    say _"I am listening..."
  end
end

dialog confirm do
  random do
    say _"Sure"
    say _"Indeed"
    say _"Absolutely"
  end
end

cancel

Cancels the current dialog flow and returns to the menu with an empty dialog stack

dialog cancel do
  random do
    say _"No problem"
    say _"Sure"
    say _"Ok"
  end
  reset
end

nothing

Stops everything and says bye

dialog nothing do
  invoke bye, :reset
end

bye

Say bye and stops the session

dialog bye do
  random do
    say _"Ok, hope to see you again one day ๐Ÿ‘‹"
    say _"Ok, see you later ๐Ÿ‘‹"
    say _"Ok, goodbye ๐Ÿ‘‹"
  end

  if ! _said_bye do
    if @settings_poll.eos_poll, do: invoke poll
    if @settings_share.eos_share, do: invoke share
  end
  _said_bye = true
  stop
end

stop

Stop all interactions until the user sends input again.

dialog stop do
  say _"Ok I'll stop until you say something againโ€ฆ"
  stop
end

Stop and reset both empty the dialog stack; reset does invoke __root__ while stop does not effectively stopping (not showing menu).

id

Returns the bots title and id

dialog id do
  say "#{bot.title}:#{bot.id}"
end

bsqd/defaults/menu

The dialog that shows the main bot skills configured in the @menu [] array. The dialog is invoked (in dialog __root__) when the dialog stack is empty

dialog menu do
  once do
    say _("What else can I do for you today?"), quick_replies: menu_options
  after
    random do
      say _("Is there anything else I can do for you?"), quick_replies: menu_options
      say _("Anything else I can help you with?")      , quick_replies: menu_options
      say _("Would you like to ask something else?")   , quick_replies: menu_options
    end
  end
end

When you overwrite menu use the variable menu_options as quick_replies; this list is dynamically built.

bsqd/defaults/identify

identify

Identifies a user either by asking for their name and email or authenticate via OAUTH provider (Google, Facebook, LinkedIn)

bsqd/defaults/forms

ask_name

Asks for the users name

dialog ask_name do
  _answer = ask _"What is your first name?",
    quick_replies: [_"skip"],
    expecting: [@named, @cancel, @stop, @nothing, @name]
  if _answer.name do
    user.first_name = _answer.name
  else
    say "Ok, maybe laterโ€ฆ"
  end
end

ask_email

Asks for the users email via an inline form

@email_form [ caption: _("What is your email address?"),
  height: "tall",
  schema: [type: "object",
  properties: [email: [type: "string",
  format: "email",
  title: _("Email")]],
  required: ["email"]], ui_schema: ["email": ["ui:placeholder": "your@email.com", "ui:autofocus": true], "ui:order": ["email", "*"]]]

dialog ask_email do
  form = @email_form
  invoke ask_user_form
end

bsqd/defaults/help

unknown

Invoked when no intent can be matched.

dialog unknown when last(user.intents) == :unknown do
  intent = :unknown
  invoke sorry_again
end

dialog unknown do
  intent = :unknown
  invoke sorry
  once do
    invoke help
  end
end

help

Provides help for users. Invoked by unknown or when user asks "help"

dialog help do
  perform collect_menu_skills
  say _("You can say the following things to me: #{_skills}")
end

sorry

Says sorry. Better to invoke unknown instead of sorry when apologizing for not understanding.

dialog sorry do
  random do
    say _("Sorry, you have to be a bit more specific please.")
    say _("I didn't quite get that, you might want to elaborate a bit.")
    say _("No sorry, I don't understand. Maybe rephrasing your question helps.")
  end
end

There is also sorry_again for repeated sorry.

bsqd/defaults/success

verify_success

Asks user for feedback on the last conversation or action. This is used for reporting and tagging unsuccesful actions in conversation.

dialog verify_success when !verify_success_stop do
  once do
    verify_success_options = [_("Yes ๐Ÿ‘"), _("No ๐Ÿ‘Ž")]
  after
    verify_success_options = [_("Yes ๐Ÿ‘"), _("No ๐Ÿ‘Ž"), _("Stop asking ๐Ÿšซ")]
  end
  ask _("Was this helpful?"), quick_replies: verify_success_options,
    expecting: [@yes, @no, entity(return: :stop, match: _("stop|don't|do not|refrain|shut up"))]
  branch do
  answer == :yes ->
    tag "result:success"
    invoke deescalate
  answer == :stop ->
    tag "result:stop"
    verify_success_stop = true
  true ->
    tag "result:failed"
    invoke escalate
  end
end

On ๐Ÿ‘Ž it escalates to the operator by default.

bsqd/defaults/escalate

escalate

Escalates to human operators by sending a studio push notification, email or by other means.

dialog escalate do
  escalate "Assistance required #{message}"
  tag "escalated"
  say _"I'm sorry I couldn't be of more help, I notified one of my colleaguesโ€ฆ"
end

deescalate

Flags an escalation conversation as de-escalated by tagging

dialog deescalate do
  say _"Great!"
  untag "escalated"
end