Action_listen, how does it work?

Hi, i am working with Rasa X 0.31.5 and Rasa 1.10.10 and python 3.7.6 and i am trying to make an utterance that shows 3 options to choose from. I would like to make 3 buttons generated from custom logic.

When i make utterances with buttons on FormAction or in the template responses, the action_listen is predicted and i can click the buttons. But when i use the fuction dispatcher.utter_message(text=message,buttons=buttons) the action_listen is not predicted and i can’t click the buttons.

So i would like to ask: how does the action_listen work? What makes it get predicted? And should i add this action to domain and stories files?

The custom logic i am trying to make looks like this:

input1 = tracker.get_slot(input1)
input2 = tracker.get_slot(input2)

url = "http://localhost:4001/api/input1="+input1+"input2="+input2
response = requests.get(url).json()

results = custom_logic(response) # returns a list of strings

message = "Please, choose one of those 3 options"
buttons = [{"title":results[0], "payload":results[0]},
           {"title":results[1], "payload":results[1]},
           {"title":results[2], "payload":results[2]}]

dispatcher.utter_message(text=message, buttons=buttons)
return []

Also, here is how its appearing in Rasa X. I can’t interact with the buttons in the “action_mostra_agenda”, it goes on to the good bye utterance “utter_encerrar” without the action_listen.

1 Like

Hi @caioreis350, welcome back to the forum!

Rasa Core predicts action_listen just like any other action, but in contrast to other actions, action_listen is not written out in the stories (it is implicit in front of every user message).

Since you use a form policy, the form’s happy path is not predicted using the stories, but using the form logic. The latter is essentially a while loop over the requested slots:

while some requested slots are not filled:
  requested_slot = the next empty slot on the list
  call the utter_ask_... action for the requested_slot
  call action_listen
  call verify action (optional)
call form's submit action

So if you want to show buttons during the form, they should come from the action_ask_... function, which can be used in place of utter_ask_....

So your custom logic should go inside an action_ask_... and that action should fill a new slot that contains the result of the button. Alternatively, if these buttons come at the end of the form, you can add the custom logic to the submit function of the form.

1 Like

you can add

return [FollowupAction("action_listen")]

at the end. That should accomplish what you want.

This might work, but followup actions should generally be avoided because they make it hard to interpret stories.