Responses

Video


Here's an example snippet from a domain.yml file that shows some example responses.

responses:
utter_greet:
- text: "Hey there!"
utter_goodbye:
- text: "Goodbye :("
utter_default:
- text: "Sorry, I didn't get that, can you rephrase?"
utter_youarewelcome:
- text: "You're very welcome!"
utter_iamabot:
- text: "I am a bot, powered by Rasa."

There is a utter_<thing> naming convention so that each response starts with "utter". Note that we very much recommend having a utter_iamabot in your domain file since because assistant should be able to explain that they are not a human.

You're not limited to static responses though. You can also define responses that are dynamic. For example, you can include more than one possible response for a specific template. Rasa will then randomly select which response to pick.

responses:
utter_greet:
- text: “Hello! How are you?
- text: “Hello there :)”
- text: “Hi. How can I help you today?
utter_goodbye:
- text: “Bye bye!

In this case, Rasa will randomly select one of the three responses whenever it needs to send the utter_greet response. You can make it even more dynamic by including slots in the responses.

slots:
name:
type: any
responses:
utter_greet:
- text: “Hello {name}! How are you?
- text: “Hello there :)”
- text: “Hi. How can I help you today?

It will also fill in the {name} variable with a slot value if there is one that's available.

Content Responses

You're also able to have responses that contain images or buttons as well!

responses:
utter_greet:
- text: "Hey! How are you?"
buttons:
- title: "great"
payload: "/mood_great"
- title: "super sad"
payload: "/mood_sad"
utter_cheer_up:
- text: "Here is something to cheer you up:"
image: "https://i.imgur.com/nGF1K8f.jpg"

You can even customise the message based on the channel that you're using.

responses:
utter_ask_game:
- text: "Which game would you like to play on Slack?"
channel: "slack"
- text: "Which game would you like to play?"

This way, slack users will be able to get a different message. You can even send custom payloads if you've made your own channel. It's an advanced use-case, but Rasa really allows you to customise what you send to the front-end.

responses:
utter_book_time:
- custom:
blocks:
- type: section
text:
text: "Book a time for your appointment:"
type: mrkdown
accessory:
type: datepicker
initial_date: "2019-05-21"
placeholder:
type: plain_text
text: "Select a date"

Training

If you want your assistant to actually use the defined responses, you will have to include them into your training stories as well. For example:

stories:
- story: greet user
steps:
- intent: greet
- action: utter_greet

Links

Exercises

Try to answer the following questions to test your knowledge.

  • Which content types can responses contain?
  • How do you create specific response templates per channel?

2016-2024 © Rasa.