I am using rasa forms to fill the slots from user. I want the whole user message to be filled in the slot. I have gone through the docs and found about slot mappings. But in my case the slots are dynamic the data.json, yml file and stories.md are all created using excel sheet so i can not create specif forms. I have created a generic form which should fill the slot with user message. But since i don’t know about the slot names i can’not create it. Please help me. Below is my code:
def slot_mappings(self): # type: # () -> Dict[Text: Union[Dict, List[Dict]]]
intent_name = tracker.latest_message['intent'].get('name')
slot_names = df['slots'][df['Intent'] == intent_name].values
slot_names = [x.strip() for x in slot_names[0].split(',')]
slot_with_value = {}
for itms in slot_names:
slot_with_value[itms]="self.from_text()"
res = ', '.join('{}: {}'.format(key, value) for key, value in slot_with_value.items())
return res
in the above code the data frame has a field as slot which is storing the slot information related to that intent. But in slot_mapping there is no tracker so i am not able to create the dictionary so that my bot stores the user message in the slot.
below is my validation function which aslo not working and storing the user message in the slot.
def validate(self, dispatcher, tracker, domain):
slot_values= self.extract_other_slots(dispatcher, tracker, domain)
slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
user_input = tracker.latest_message['text']
requested_slot = self.request_next_slot(dispatcher, tracker, domain)
requested_slot = [elem['value'] for elem in requested_slot]
intent_name = tracker.latest_message['intent'].get('name')
slot_names = df['slots'][df['Intent'] == intent_name].values
slot_names = [x.strip() for x in slot_names[0].split(',')]
if slot_to_fill:
slot_values.update(self.extract_requested_slot(dispatcher,tracker, domain))
if not slot_values:
# reject form action execution
# if some slot was requested but nothing was extracted
# it will allow other policies to predict another action
raise ActionExecutionRejection(self.name(),
"Failed to validate slot {0} "
"with action {1}"
"".format(slot_to_fill,
self.name()))
for slot, value in slot_values.items():
if slot in slot_names:
if value is None:
dispatcher.utter_message("Plese provide {}".format(slot))
slot_values[slot] = None
else:
dispatcher.utter_message("Plese provide {}".format(slot))
slot_values[slot] = user_input
return [SlotSet(slot, value) for slot, value in slot_values.items()]
It rather executes ActionExecutionRejection after user gives some input. How can i handle this. Please help