Hi there, I am using RASA V2. I have CustomForm. In this form i have slot named “deployment_date” and it is getting its value from entity date. In RASA V1 this code was perfectly working. When user says “Bu akşam sürüm dışı çıkabilliir miyim?” this CustomForm’s validate_deployment_date function was working and doing its job. But after V2 it is not working. It works only if i define entity as same name with slot name (Before my example had entity with name “date”, but now i had to change them to “deployment_date”) I think i am miissing soomething. Because i have many forms and those forms also have date type slots and if i change every entity with their relating slot names it will be huge change. Does anyone know how can i make it work?
Here is my Form:
class SurumDisiUygunlukForm(CustomFormAction):
def name(self) -> Text:
return "bt_sco_surum_surumdisi_gun_uygunluk_form"
@staticmethod
def required_slots(tracker):
return [ "deployment_date", "control_confirmation", "confirmation" ]
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
return {
"deployment_date": [
self.from_entity(entity="time"),
self.from_text()
],
"control_confirmation": [
self.from_text()
],
"confirmation": [
self.from_intent(value=True, intent="confirmation_tr"),
self.from_intent(value=False, intent="cancellation_tr")
]
}
def request_next_slot(
self,
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: Dict[Text, Any],
) -> Optional[List[EventType]]:
"""Request the next slot and utter template if needed,
else return None"""
active_intent_name = tracker.latest_message["intent"].get("name")
for slot in self.required_slots(tracker):
if self._should_request_slot(tracker, slot):
logging.error(f"Request next slot '{slot}'")
if slot == "control_confirmation":
deployment_date = tracker.slots.get("deployment_date")
try:
logging.error("alper deployment_date {}".format(deployment_date))
api_service = ApiService("")
if "." in deployment_date:
logging.error("alperttt1")
deployment_date = deployment_date.split(".")[0]
logging.error("alperttt2")
deployment_date = api_service.format_date_time(deployment_date)
logging.error("alperttt3")
except Exception as e:
print("an errr occured!",e)
deployment_date = tracker.slots.get("deployment_date")
## Tarih : Saat, için özel gün ve freeze kontrolünü yapacağım. Emin misin ? hayır dediğinde, tarih ve saat al , evet dediğinde devam et.
dispatcher.utter_message(text=deployment_date + " için özel gün ve freeze kontrolünü yapacağım. Onaylıyor musunuz? ('Evet' ya da 'Hayır' diyebilirsiniz.)")
return [
SlotSet(REQUESTED_SLOT, "confirmation"),
SlotSet("control_confirmation", "duration_time"),
SlotSet("confirmation", None),
SlotSet("intent_name", active_intent_name)
]
else:
dispatcher.utter_message(template=f"utter_ask_{slot}", **tracker.slots)
return [SlotSet(REQUESTED_SLOT, slot), SlotSet("intent_name", active_intent_name)]
# def validate_deployment_date(
# self,
# value: Text,
# dispatcher: CollectingDispatcher,
# tracker: Tracker,
# domain: Dict[Text, Any],
# ) -> Dict[Text, Any]:
# logging.error("deployment_date")
# logging.error(type(value))
# logging.error(value)
# return {"deployment_date": value}
@staticmethod
def get_date_range_or_val(value) -> Text:
logging.error("get_date_value: {}".format(value))
if value and isinstance(value,list) and len(value) > 1:
value = dict(zip(['from','to'] ,value ))
if isinstance(value,str) or isinstance(value,dict):
value = [value]
logging.error(value)
if value and isinstance(value,list) and len(value) > 0:
if len(value) > 1 and "from" in value[1]:
logging.error("FROM1")
value = value[1]["from"]
elif "from" in value[0]:
logging.error("FROM2")
value = value[0]["from"]
else:
if isinstance(value,list):
if len(value) > 1:
value = value[1]
else:
value = value[0]
logging.error("get_date_range_or_val value: {}".format(value))
return value
def validate_deployment_date(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
# logging.error("deployment_date")
# logging.error(tracker.get_slot("deployment_date"))
# logging.error("next")
# logging.error(next(tracker.get_latest_entity_values("time"), None))
logging.error("Alper value ne geldi {}".format(value))
prev_value = tracker.get_slot("deployment_date")
logging.error("Prev value: {}".format(prev_value))
##next_value = next(tracker.get_latest_entity_values("time"), None)
next_value=utils.get_entity_details(tracker,"time","duckling")
logging.error("next value: {}".format(next_value))
value=next_value
if next_value:
next_value = self.get_date_range_or_val(next_value)
logging.error("validate_deployment_date next: {} prev: {}".format(next_value,prev_value))
retVal = None
is_control_confirmation = False
try:
if prev_value and next_value and prev_value != next_value:
is_control_confirmation = True
value = next_value
logging.error(is_control_confirmation)
if not is_control_confirmation and tracker.get_slot("deployment_date") is not None:
logging.error(is_control_confirmation)
return {"deployment_date": tracker.get_slot("deployment_date")}
logging.error("alper1")
if is_control_confirmation:
logging.error("alper2")
retVal = value
else:
logging.error("alper3 {}".format(value))
retVal = self.get_date_range_or_val(value)
except Exception as e:
print("deployment_date EXCEPTION")
print(e)
if is_control_confirmation:
return {"control_confirmation": None, "deployment_date": retVal}
else:
return {"deployment_date": retVal}
def validate_confirmation(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
prev_value = tracker.get_slot("deployment_date")
next_value2 = next(tracker.get_latest_entity_values("time"), None)
next_value=utils.get_entity_details(tracker,"time","duckling")
logging.error("Alper value ne geldi {}".format(value))
logging.error("Alper value pne geldi {}".format(prev_value))
logging.error("Alper value nne geldi {}".format(next_value))
logging.error("Alper value nne2 geldi {}".format(next_value2))
if next_value:
next_value = self.get_date_range_or_val(next_value)
if prev_value and next_value and prev_value!=next_value:
return{"deployment_date": next_value,"control_confirmation" : None, "confirmation": None}
if next_value:
return {"deployment_date": next_value,"control_confirmation" : True, "confirmation": True}
return {"control_confirmation" : value, "confirmation": value}
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
deployment_date = tracker.slots.get("deployment_date")
print(deployment_date)
message_text = ""
try:
logging.error("Alper nerdeyim {}".format(deployment_date))
if tracker.slots.get("confirmation"):
# a_current_year = datetime.datetime.now()
# a_current_year = a_current_year.strftime("%Y")
# a_current_year = int(a_current_year)
bt_date_year = ""
bt_date_month = ""
bt_date_day = ""
if deployment_date:
dt = parse(deployment_date)
_date = dt.date()
bt_date_year = _date.strftime("%Y")
bt_date_year = int(bt_date_year)
# if bt_date_year > a_current_year:
# bt_date_year = a_current_year - 1
bt_date_month = _date.strftime("%m")
bt_date_day = _date.strftime("%d")
score_service = service.ScoreApiService()
is_special_day, is_any_error = score_service.get_special_days_data("Year="+str(bt_date_year)+"&Month="+str(bt_date_month)+"&Day="+str(bt_date_day)+"&IsSpecialDay=true")
if is_any_error:
raise Exception
else:
if is_special_day:
activitiyDate = is_special_day["ActivityDate"]
activityName = is_special_day["ActivityName"]
message_text = "Değişiklik takvimine göre sürüm dışı çıkamazsınız. “" + activitiyDate + " tarihi " + activityName + "” olarak belirtilmiştir. Yardımcı olabileceğim başka bir konu var mıdır?"
else:
freezedate = tracker.slots.get("deployment_date")
freezedate = freezedate.split(".")[0]
message_text = score_service.get_freeze_days_data("ActivityDate=" + freezedate)
dispatcher.utter_message(text=message_text)
else:
dispatcher.utter_message(template="utter_group_anything_else")
except Exception as e:
print(e)
dispatcher.utter_message(template="utter_exception")
return [AllSlotsReset()]