Customize last question of rasa form depending on the slot value

I have a ninimum valuable example of a Rasa form. I am using Rasa 2.5.

The story is simple: The bot asks the user with utter_customer (which is a button) if he already is a customer of Starbucks. If the customer affirms with intent affirm, then the the bot starts a form name_form which asks the user (=customer of Starbucks) about his first name and last name and fills the corresponding slots first_name and last_name, respectively. If the customer denies that he is a customer of Starbucks by pushing the deny button, the same form starts and asks about his first name and last name and fills the corresponding slots first_name and last_name, respectively.

As you can see in the domain.yml-file below, utter_customer will set a slot wether the user has custom_status = customer or custom_status = no customer

stories.yml:

version: "2.0"

stories:

- story: introduction
  steps:
  - intent: greet
  - action: utter_greet
  - action: utter_customer


- story: form for customer
  steps:
  - intent: affirm
  - action: utter_greet_customer
  - action: name_form
  - active_loop: name_form
  - slot_was_set:
    - requested_slot: first_name
  - slot_was_set:
    - first_name: vincent
  - slot_was_set:
    - requested_slot: last_name
  - slot_was_set:
    - last_name: vincent-mcvincent
  - slot_was_set:
    - requested_slot: null
  - active_loop: null
  - action: utter_submit
  - action: utter_slots_values

- story: form for non customer
  steps:
  - intent: deny
  - action: utter_greet_non_customer
  - action: name_form
  - active_loop: name_form
  - slot_was_set:
    - requested_slot: first_name
  - slot_was_set:
    - first_name: vincent
  - slot_was_set:
    - requested_slot: last_name
  - slot_was_set:
    - last_name: vincent-mcvincent
  - slot_was_set:
    - requested_slot: null
  - active_loop: null
  - action: utter_submit
  - action: utter_slots_values

Since I still don’t know how to write compact and short forms, some parts of the form name_form is specified in rules.yml. Important to note is, that the

rules.yml:

version: "2.0"

rules:

- rule: Submit form
  condition:
  - active_loop: name_form
  steps:
  - action: name_form
  - active_loop: null
  - slot_was_set:
    - requested_slot: null
  - action: utter_submit
  - action: utter_slots_values

Here are the most important pieces of the domain.yml-file:

version: '2.0'
session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

intents:
- greet
- deny
- request_names
- goodbye
- affirm

entities:
- customer_status

slots:
  first_name:
    type: text
    influence_conversation: true
  last_name:
    type: text
    influence_conversation: true
  customer_status:
    type: text
    influence_conversation: false

responses:

  utter_ask_first_name:
  - text: What is your first name?

  utter_ask_last_name:
  - text: What is your last name?

  utter_submit:
  - text: Ok. Thanks!

  utter_greet_customer:
  - text: Hello customer!

  utter_greet_non_customer:
  - text: Hello non-customer!

  utter_slots_values:
  - text: I will remember that your name is {first_name} {last_name}!

  utter_customer:
  - text: Are you already a customer of Starbucks?
    buttons:
      - payload: /affirm{{"customer_status":"customer"}}
        title: Yes
      - payload: /deny{{"customer_status":"no customer"}}
        title: No

actions:
- validate_name_form

forms:
  name_form:
    first_name:
    - type: from_text
    last_name:
    - type: from_text

I have the following question. Depending of the slot custom_status I want the form form_name request one more slot. If the user is a customer (custom_status = customer), I want the form trigger the question for the customer ID. If the the user is not not customer, I want the form form_name to ask for the user’s city name.

In other words: How can I customize the very last question of my form depending on the slot value of custom_status?

Hope you can help me!

Hi @Chatbot_Ra

You can customize the required slots by writing an if else logic inside your required_slots method to check the value of the custom_status and then return 2 sets of required slots.