DEV Community

Cover image for RASA - OR statements
Petr Janik
Petr Janik

Posted on • Updated on

RASA - OR statements

Another way to write shorter stories, or to handle multiple intents the same way, is to use an or statement.

For example, if you ask the user to confirm something, and you want to treat the affirm and thankyou intents in the same way. The story below will be converted into two stories at the training time:



# stories.yml
# ... previous content ...
  - story: confirm by affirm or thankyou
    steps:
      - intent: confirm
      - action: utter_ask_confirm
      - or:
          - intent: affirm
          - intent: thankyou
      - action: utter_confirmed


Enter fullscreen mode Exit fullscreen mode

For this example to work, apart from the code we have from the previous chapters, I have created two new intents:



# data/nlu.yml
# ... previous content ...
  - intent: confirm
    examples: |
      - can I confirm
      - I want to confirm
      - I would like to confirm that
  - intent: thankyou
    examples: |
      - thank you
      - thanks
      - thanks a lot
      - thank you so much!


Enter fullscreen mode Exit fullscreen mode

and added them to domain.yml:



# domain.yml
# ... previous content ...
intents:
  # ... previous intents ...
  - confirm
  - thankyou


Enter fullscreen mode Exit fullscreen mode

We need the chatbot's responses as well:



# domain.yml
# ... previous content ...
  utter_ask_confirm:
    - text: Do you really want to confirm that?
  utter_confirmed:
    - text: Confirmed.


Enter fullscreen mode Exit fullscreen mode

Let's see this in action:

Conversation with OR first

Conversation with OR second

You can learn more about OR statements in the documentation.

In the next chapter, we will look at slots in detail.

Repository for this tutorial:

You can checkout the state of the repository at the end of this tutorial by running:



git clone --branch 14-or-statements git@github.com:petr7555/rasa-dev-tutorial.git


Enter fullscreen mode Exit fullscreen mode

Top comments (0)