In a form, how would you go about uttering a different message if the answer to a requested slot did not validate? In some cases, if the user answers something wrong, I’d like to provide more information so that they have an easier time answering the message (or give more context). It could also be useful the other way around: give a bit more context initially but if we need to repeat the question, write a shorter utterance.
Thanks for your answer @saurabh-m523! That would indeed work for some cases but only as a separate message before repeating the question. That works well but doesn’t give me the flexibility I need in some cases unfortunately.
Well I couldn’t think of anything other than overriding the request_next_slot method if you want to modify the way the slots are being asked. Look into it, maybe that could help.
I had the same problem today and this is how I solved it:
My use-case is for when users provide an answer that needs to be of a certain length.
Pre step: Handle your utter_ask_<slot_name> in the action server instead. In other words, convert it into an action_ask_<slot_name>. Let’s call it action_ask_answer for this example.
My validate function goes as normal. If the response is less than 5 words long, it fills the slot with “None”. This also dispatchers an utterance, let’s call it utter_too_short.
Step #1 prompts rasa to activate action_ask_answer again, so the action server receives a request to run it.
Inside action_ask_answer, I extract the second to latest event to see if utter_too_short ever happened using a try/except block:
I only repeat the message when template is notutter_too_short:
if template != "utter_too_short":
dispatcher.utter_message(template="utter_ask_answer")
This also works great when you are validating for other things that may require the repeated message. For example, when my users answer in a non-English language, I want to be able to say utter_not_english followed by utter_ask_answer