I need a detailed example of how dynamic behviour of form is implemented This is something I am refering to in rasa docs
below is my use case:-
there would be a form where user would provide a counterparty name to get trade data. Then user would be asked to provide whether he needs “All data” or “within a date range”. If he chooses date range then two additional slots would be added to required slots ie. start_date and end_date to be filled by form. please refer below snapshot for the workflow
Is there any way to define slot mappings to these additional slot so that dates are extracted automatically from regex or duckling service.I could’nt find a way of doing this, so implemented a extract_start_date and extract_end_date method to extract dates using regex. But, even in this case when bot asks for utter_ask_start_date and user provides a date, same date is getting extracted withing extract_end_date as well (though this slot wasn’t asked yet). And, as both slots are form gets deactiavated and goes to next action for submit with incorrect details.
BOTH extract_start_date and extract_end_date are getting invoked when user gives only start_date. below is the code snippet for Formvalidation.
class ValidateCounterpartyListForm(FormValidationAction):
def name(self) -> Text:
return "validate_counterparty_name_list_form"
async def required_slots(
self,
slots_mapped_in_domain: List[Text],
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: "DomainDict",
) -> Optional[List[Text]]:
additional_slots = []
print("timneline==",tracker.get_slot('trade_timeline'))
if tracker.get_slot('trade_timeline') == "date_range":
additional_slots.append("start_date")
additional_slots.append("end_date")
return additional_slots + slots_mapped_in_domain
async def extract_start_date(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> Dict[Text, Any]:
text_of_last_user_message = tracker.latest_message.get("text")
date_regex="^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$"
date_search = re.search(date_regex, text_of_last_user_message, re.IGNORECASE)
if date_search:
start_date = date_search.group(1)+date_search.group(2)+date_search.group(3)
print("setting start date to ", start_date)
return {"start_date": start_date}
return {"start_date": None}
async def extract_end_date(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> Dict[Text, Any]:
text_of_last_user_message = tracker.latest_message.get("text")
date_regex="^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$"
date_search = re.search(date_regex, text_of_last_user_message, re.IGNORECASE)
if date_search:
end_date = date_search.group(1)+date_search.group(2)+date_search.group(3)
print("setting end date to ", end_date)
return {"end_date": end_date}
return {"end_date": None}