These are my required_slots in my domain file.
forms:
basic_info_form:
required_slots:
- options
- language
- phone
- phone_type
- contact_prefer
- confirm_phone
- other_phone
- street_address
- city
- zipcode
- confirm_address
- full_address
- home_members
- race
- hispanic
- gender
I want the form to ask for the required slot in given sequence, but I have some conditions -
- If the value of contact_prefer is ‘phone_call’ or ‘text’, the form should ask for the confirm_phone slot, else skip it and go direct to street_address.
- If the value of confirm_phone is ‘other’, then it should ask for other_phone slot, and then continue to street_address.
- If the value of confirm_address is ‘no’, then the form should ask for full_address slot, and then continue to the home_members slot. Else, continue directly to home_members slot.
I tried doing it using dynamic form behavior, but I am not able to make it work.
This is my actions file:
from typing import Any, Text, Dict, List, Union
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormValidationAction
from rasa.nlu.utils import write_json_to_file
from rasa_sdk.events import SlotSet
class ActionSubmitForm(Action):
def name(self) -> Text:
return "action_submit_form"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text,Any])->List[Dict[Text,Any]]:
#id= trunc(time())
write_json_to_file('output/slots_values.json', tracker.slots)
return []
class ValidateBasicInfoForm(FormValidationAction):
def name(self) -> Text:
return "validate_basic_info_form"
async def required_slots(
self,
domain_slots: List[Text],
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text,Any],
) -> List[Text]:
additional_slots = [""]
if tracker.slots.get("contact_prefer") in ['phone_call','text(SMS)']:
additional_slots.append("confirm_phone")
return additional_slots + domain_slots
async def extract_confirm_phone(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict
) -> Dict[Text, Any]:
confirm_phone = tracker.latest_message.get("text")
SlotSet("confirm_phone",confirm_phone)
Right now, I am only trying to do it to check the value of the confirm_prefer slot and extract the value of the confirm_phone slot. However, the form gets stuck on the contact_prefer slot and keeps asking the same question, no matter the input.
Below is my domain file. Does anyone know what I am doing wrong?
version: "3.1"
config:
store_entities_as_slots: true
intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
slots:
options:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: options
language:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: language
phone:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: phone
phone_type:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: phone_type
contact_prefer:
type: text
influence_conversation: true
mappings:
- type: custom
action: validate_basic_info_form
conditions:
- active_loop: basic_info_form
confirm_phone:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: phone_type
other_phone:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: other_phone
street_address:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: street_address
city:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: city
zipcode:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: zipcode
confirm_address:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: phone_type
full_address:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: full_address
home_members:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: home_members
race:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: race
hispanic:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: hispanic
gender:
type: text
influence_conversation: false
mappings:
- type: from_text
conditions:
- active_loop: basic_info_form
requested_slot: gender
responses:
utter_greet:
- text: "Hello!\nI'm Lucky. Do you need any help?"
utter_ask_options:
- text: "What do you need help with?\n1) Financial Advice\n2) Housing Questions"
utter_ask_language:
- text: "All right, I hope to help you with that.\nFirst, let's get to know each other. My primary language is English, but I am learning how to speak more languages. \nWhat is you primary language?\n -English\n -Spanish\n -Other"
utter_ask_phone:
- text: "That's awesome! My phone number is 214-739-6151. What yours?"
utter_ask_phone_type:
- text: "Please tell me which type of phone is this? \n Cell Phone \n Home Phone"
utter_ask_contact_prefer:
- text: "Wow so many ways to talk to you. How do you prefer I get in touch with you in the future? \n Email \n Phone Call \n Text(SMS)"
utter_ask_confirm_phone:
- text: "Which number should I use to reach out to you later? \n{phone} \nOther"
utter_ask_other_phone:
- text: "What is the new number you want me to reach you through?"
utter_ask_street_address:
- text: "Great! Did you know my home address is this website. What's your address?"
utter_ask_city:
- text: "What city do you live in?"
utter_ask_zipcode:
- text: "Oh nice! What is your Zip code?"
utter_ask_confirm_address:
- text: "Perfect. Can you verify that this is your full address?\n {street_address},{city} - {zipcode} \n- Yes\n- No"
utter_ask_full_address:
- text: "Oh no! Please help me correct it."
utter_ask_home_members:
- text: "I'm the only chatbot that lives on this webpage. How many people live at your household including you?"
utter_fascinated:
- text: "Oooh ok. You know, I have always been fascinated by humans. There is so much diversity in mankind.\nI am interested to know what type of human you are but please feel free to choose \"prefer not to say\" if you do not want to answer my next few questions."
utter_ask_race:
- text: "What ethnicity/race are you? \n-Black / African American\n-Native Hawaiian or other Pacific Islander\n-White\n-American Indian or Alaskan Native\n-Asian\n-More than one race / Other\n-Prefer Not To Say"
utter_ask_hispanic:
- text: "Are you Hispanic/Latino?\n-Yes\n-No\n-Prefer Not To Say"
utter_ask_gender:
- text: "Fun fact: I have no gender. What gender are you?\n-Female\n-Male\n-Gender Non-Conforming\n-Prefer Not To Say"
utter_goodbye:
- text: "Bye"
utter_thank_you:
- text: "Thank you for bearing with me! I learned a lot about you which will help me help you. \nI just have a few more questions to ask you..."
utter_iamabot:
- text: "I am Lucky, your online assitant."
actions:
- action_submit_form
- validate_basic_info_form
forms:
basic_info_form:
required_slots:
- options
- language
- phone
- phone_type
- contact_prefer
- confirm_phone
- other_phone
- street_address
- city
- zipcode
- confirm_address
- full_address
- home_members
- race
- hispanic
- gender