I am building a chatbot for table reservation in a hotel. I have written a custom action to validate and modify the extracted user input. I want to reset my slot and ask the question again if the flag value is False. Here’s my actions.py file:
from typing import Any, Text, Dict, List, Union
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, UserUtteranceReverted, EventType, AllSlotsReset
from rasa_sdk.executor import CollectingDispatcher
from word2number import w2n
from .functions import util
class ValidateRestaurantForm(Action):
def name(self) -> Text:
return "user_details_form"
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict) -> List[EventType]:
required_slots = ["number_table", "table_type", "reserve_time"]
for slot_name in required_slots:
if tracker.slots.get(slot_name) is None:
# The slot is not filled yet. Request the user to fill this slot next.
return [SlotSet("requested_slot", slot_name)]
# All slots are filled.
return [SlotSet("requested_slot", None)]
class ActionSubmit(Action):
def name(self) -> Text:
return "action_submit"
def run(
self,
dispatcher,
tracker: Tracker,
domain: "DomainDict",
) -> List[Dict[Text, Any]]:
number_table = tracker.get_slot("number_table")
number_table = w2n.word_to_num(number_table)
table_type = tracker.get_slot("table_type")
reserve_time = tracker.get_slot("reserve_time")
flag, reserve_time_modified = util(reserve_time)
if flag == False:
dispatcher.utter_message(response="utter_deny_reserve_time")
dispatcher.utter_message(response="utter_ask_reserve_time")
return [SlotSet("reserve_time", None)] <-------Resetting the slot and ask
reservation time again
else:
dispatcher.utter_message(response="utter_submit",
number_table=number_table,
table_type=tracker.get_slot("table_type"),
reserve_time=reserve_time_modified)
return [AllSlotsReset()]
I am getting this flag value from a different function “util” which takes as input the reservation time and checks if the reserve_time is in the range (7pm to 10 pm). If it is in the range then it returns True otherwise return False. Please suggest some ideas to solve this problem. I am a beginner in Rasa. Thanks in advance.