Hi, i try to validate a slot for which multiple entity inputs where found in a single message. In that case the variable ‘value’ in validate_{slot_to_validate} is a list of the extracted entities.
My idea was to let the user choose which entity he wants to map to the slot via a button message. Therefore I wrote this functions within my FormAction which gets called in the validate_{slot} function
# result_list here contains the possible slot values
def _ambiguous_result(self,dispatcher,tracker: Tracker,domain,result_list):
logger.debug('Handling ambiguous results.')
buttons = list()
for result in result_list:
payload = json.dumps({tracker.get_slot('requested_slot'): result})
buttons.append({'title': result,
'payload': '/answer ' + payload,
'type': 'button-bot',
'style': 'inlineButton'})
payload = json.dumps({tracker.get_slot('requested_slot'): None})
buttons.append({'title': domain['templates'].get('ambigous_none_button'),
'payload': '/answer ' + payload,
'type': 'button-bot',
'style': 'inlineButton'})
logger.debug(f'Number of buttons = {len(buttons)}')
dispatcher.utter_message("This output gets uttered!")
dispatcher.utter_button_message('This does not',buttons)
return
While the pure text messages is uttered by the bot the button message is completely lost. However its mentioned in the debug output
DEBUG rasa.core.processor - Action 'move_form' ended with events '['BotUttered(text: This output gets uttered!, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, metadata: {})', 'BotUttered(text: This does not, data: {"elements": null, "quick_replies": null, "buttons": [{"payload": "/answer {\\"taxid\\": \\"1011121314152\\"}", "style": "inlineButton", "title": "1011121314152", "type": "button-bot"}, {"payload": "/answer {\\"taxid\\": \\"1011121314153\\"}", "style": "inlineButton", "title": "1011121314153", "type": "button-bot"}, {"payload": "{\\"taxid\\": null}", "style": "inlineButton", "title": [{"text": "Keine"}], "type": "button-bot"}], "attachment": null, "image": null, "custom": null}, metadata: {})', 'BotUttered(text: Wie lautet Ihre Steuernummer?, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, metadata: {"move_date": null, "requested_slot": "taxid", "residence": null, "taxid": null})', 'SlotSet(key: taxid, value: None)', 'SlotSet(key: requested_slot, value: taxid)']'
So, why is the button message not visible at all? It works in general (for example in the TwoStageFallbackPolicy).
What are the alternatives to handle two valid slot values? I might just throw away everything and ask the user for the same slot again. Any other ideas?
EDIT: Test above were done in the rasa shell on command line. Tried the Rasa X UI instead. There the message text of the button message gets displayed, but no buttons are displayed and it jumps right to the next action.
Also giving the validate action for completeness:
def validate_taxid(self, value,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> Dict[Text, Any]:
logger.debug(f"Tracker latest message: {tracker.latest_message}")
taxid_regex = re.compile(r'\d{13}')
candidate_list = []
# multiple entities end up here as a list
if type(value) == type([]):
logger.debug(f"Found multiple entities of taxid in message {tracker.latest_message.get('text')}")
for taxid in value:
if taxid_regex.match(taxid):
candidate_list.append(taxid)
# no entities found, trying to extract them from text
elif tracker.latest_message.get('entities') == []:
candidate_list = taxid_regex.findall(value)
else:
if taxid_regex.match(value):
candidate_list = [value]
logger.debug(f'Candidate list in taxid {candidate_list}')
if len(candidate_list) == 0:
dispatcher.utter_template('utter_not_understood',tracker)
dispatcher.utter_template('utter_advice_taxid',tracker)
return {'taxid' : None}
elif len(candidate_list) > 1:
self._ambiguous_result(dispatcher, tracker, domain, candidate_list)
return {'taxid' : None}
else:
return{'taxid': candidate_list[0]}
rasa==1.1.5 rasa-sdk==1.1.0 rasa-x==0.19.4