RASA - requested_slot
Tags: rasa, chatbot, nlp, ai
Published: 2021-04-29 16:52:05

`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.

```yml
# 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.
```yml
# 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`.
```yml
# domain.yml
# ... previous content ..
intents:
  # ... previous intents ..
  - explain
```

Now, let's create responses explaing to the user why the chatbot needs certain information.
```yml
# 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:
```yml
# 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`.

![Chat with explaining email and frequency](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2k1fkqckah94469qdya2.png)

So cool!

You can learn more about `requested_slot` in the [documentation](https://rasa.com/docs/rasa/forms#the-requested_slot-slot).

In the next chapter, we will look at sessions.

Repository for this tutorial:
{% github petr7555/rasa-dev-tutorial no-readme %}

You can checkout the state of the repository at the end of this tutorial by running:
```bash
git clone --branch 10-requested-slot git@github.com:petr7555/rasa-dev-tutorial.git
```