Petr Janik
Posted on April 29, 2021
requested_slot
is a special slot that is automatically added to the domain with type text
. Its value is the name of the next slot that will be filled during the form loop. This value will be ignored during conversations by default.
If you want to change this behavior, you need to add the requested_slot
to your domain file as a categorical slot with influence_conversation
set to true.
# domain.yml
# ... previous content ...
slots:
# ... previous slots ...
requested_slot:
type: categorical
influence_conversation: true
values:
- email
- frequency
Here we are also declaring what values we expect this slot to have.
You might want to do this if you want to handle your unhappy paths differently, depending on what slot is currently being asked from the user. For example, if the user responds to one of the chatbot's questions with another question, like "Why do you need to know that?", the response to this explain intent depends on where we are in the story.
Let's create the explain intent.
# data/nlu.yml
# ... previous content ..
- intent: explain
examples: |
- why
- why do you need to know that
- why should i give you this information
- why are you asking?
- why is this needed?
And add it to domain.yml
.
# domain.yml
# ... previous content ..
intents:
# ... previous intents ..
- explain
Now, let's create responses explaing to the user why the chatbot needs certain information.
# domain.yml
# ... previous content ...
utter_explain_email:
- text: So that I know where to send it.
utter_explain_frequency:
- text: So that I know how often to send it.
Create three new stories:
# data/stories.yml
# ... previous content ...
- story: explain email
steps:
- intent: subscribe
- action: newsletter_form
- active_loop: newsletter_form
- slot_was_set:
- requested_slot: email
- intent: explain
- action: utter_explain_email
- action: newsletter_form
- story: explain frequency
steps:
- intent: subscribe
- action: newsletter_form
- active_loop: newsletter_form
- slot_was_set:
- requested_slot: email
- slot_was_set:
- requested_slot: frequency
- intent: explain
- action: utter_explain_frequency
- action: newsletter_form
- story: explain both email and frequency
steps:
- intent: subscribe
- action: newsletter_form
- active_loop: newsletter_form
- slot_was_set:
- requested_slot: email
- intent: explain
- action: utter_explain_email
- action: newsletter_form
- slot_was_set:
- requested_slot: frequency
- intent: explain
- action: utter_explain_frequency
- action: newsletter_form
Let's try our assistant: rasa train && rasa shell
.
So cool!
You can learn more about requested_slot
in the documentation.
In the next chapter, we will look at sessions.
Repository for this tutorial:
You can checkout the state of the repository at the end of this tutorial by running:
git clone --branch 10-requested-slot git@github.com:petr7555/rasa-dev-tutorial.git
Posted on April 29, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.