@_daisy
In my case, I used this code in the form validation action to extract properties of Duckling “duration” entity from “q5_duration” slot in order to set a custom slot, “q6_ending_time”:
from typing import Dict, Text, Any, List
from rasa_sdk import Action, Tracker, FormValidationAction
from rasa_sdk.events import SlotSet, UserUtteranceReverted, EventType
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict
from datetime import datetime, timedelta
class ValidateRoomReservationForm(FormValidationAction):
def name(self) -> Text:
return "validate_room_reservation_form"
def validate_q1_location(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate location value."""
(...)
def validate_q2_date(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate date value."""
(...)
def validate_q3_number_of_participants(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate number of participants value."""
(...)
def validate_q4_starting_time(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate starting time value."""
(...)
def validate_q5_duration(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate starting time value."""
starting_time = tracker.get_slot('q4_starting_time')
starting_time_converted = datetime.fromisoformat(starting_time)
duration_unit = tracker.latest_message['entities'][0]['additional_info']['unit']
if duration_unit == 'second':
duration_in_seconds = slot_value
elif duration_unit == 'minute':
duration_in_seconds = slot_value * 60
elif duration_unit == 'hour':
duration_in_seconds = slot_value * 3600
ending_time = starting_time_converted + timedelta(seconds = duration_in_seconds)
return{"q5_duration": slot_value, "q6_ending_time": ending_time.isoformat()}