Dynamic utter_ask in form

Hello, I want to fill a form that requieres a dynamic utter_ask message that depends on the previous answers. Is there any way to achive this? For example:

utter_ask_car_version:
  - text: "F). Versión"

and the running form would look like:

F). Versión

  1. V1
  2. V2

in which the list lenght is variable and then select one option.

Hello :slight_smile:

You can use a Custom Action with the name action_ask_message.

1 Like

May you provide a simple example or how would I “pass” the information to the utter_ask?

Would something like this work?

utter_ask_car_version:
  - text: "F). Versión {Info}"

dispatcher.utter_message(template="utter_ask_car_version",
                                 Info="\n *V1 \n *V2 \...",
1 Like

Sure!

Since you’re using forms you probably know about slots, but maybe you need to read about custom actions.

The same way you should ask for a slot named my_slot in an utterance named utter_ask_my_slot, you could instead use a custom action named action_ask_my_slot (ref).

So, completely remove utter_ask_car_version, and, in actions.py, add the following:

class ActionAskCarVersion(Action):
    def name(self):
        return "action_ask_car_version"

    def run(self, dispatcher, tracker, domain):
        info = tracker.get_slot("info") # Replace "info" with the name of the slot you want to use to decide what to utter

        if info = "ABC"
            dispatcher.utter_message(text = f"F). Versión {info}")
        elif info = "DEF"
            dispatcher.utter_message(text = "Another answer")

        return []

Of course this is just an example, you can do whatever you want inside a custom action!


Look at this action (line 844). It’s not an action to ask for a slot, but it does different things depending on the values of the slots topic_type, account_type, and service_type. The action is not complete at all and badly written, but the skeleton/logic is here.

1 Like