How to force the action of listening

Hello everyone,

I need to force the “action_listen” in one step of my stories, but I couldn’t do it.

I tried to add it in the same story, and through custimized actions.

My story:

## StoryFallback - Generar Ticket - Ayudar en algo mas - No eso es todo - Bien
* GenerarTicket
    - utter_fallback_ticket
    - action_create_ticket
    - action_listen
    - action_create_ticket_before
    - utter_act_menu_otros_epa

Customized Action:

class ActionCreateTicket(Action):
    def name(self):
        return "action_create_ticket"

    def run(self, dispatcher, tracker, domain):
        print("Create Ticket")
        msg = tracker.latest_message.get('text')
        print(msg)
        dispatcher.utter_template("utter_fallback_ticket", tracker)

        return[FollowupAction('action_listen')]

Hello @SpyrosCapetanopulos,

I don’t know if you can put action_listen in the middle like that. Normally action_listen is automatically executed at the end of each intent, so i think if you declare 5 actions like that it will always go through those 5 actions, which means it did execute action_listen in the middle, but didn’t wait for the user’s input and simply keep executing the follow up actions (although i’m not 100% sure about it, just my guess).

Secondly, if you need to receive user input in the middle of a process like that, why not split it into multiple intents, or use a FormAction ? Those approaches might be more suitable for the situation.

Hello @fuih,

Thanks for the answer, I am new to this from RASA, but if you have any example of FormAction that can help me I would greatly appreciate it.

Thanks!

The general idea is that you declare a number of slots corresponding to the data which you want to ask the user to provide, i.e: name, age, product, etc,… This is called required_slots in FormAction.

After executing the FormAction, the bot will automatically ask for all the required slots sequentially with the utterances that you provide for each of them. You can also perform validating data in FormAction, if the user enters something invalid, you can make the bot ask the user again.

After the required slots are filled (which means the user provided all the necessary information), the FormAction will execute a submit function, which you will implement to do your logic with all the provided information from the user.

There are a lot of complex interaction which you can achieve by combining FormAction and Events together.

You can read about the FormAction here: Forms

Also check out Events when you are familiar with FormAction: Events

1 Like

@fuih

Thanks for the help, but perform the steps explained in the documentation provided but give me this Error:

ERROR rasa_sdk.endpoint - Failed to extract slot ticket with action ticket_form

The Stories:

## Story Fallback - Generar Ticket
* GenerarTicket
    - ticket_form
    - form{"name": "ticket_form"}
    - form{"name": null}

FromAction:

class ActionFromTicket(FormAction):
    def name(self) -> Text:
        print("NAME")
        return "ticket_form"

    @staticmethod
    def required_slots(tracker: Tracker) -> List[Text]:
        print("Required Slots")
        return ["ticket"]

    def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        print("Required Slots")
        return {"ticket": self.from_entity(entity="ticket")}

    def submit(self,
               dispatcher: CollectingDispatcher,
               tracker: Tracker,
               domain: Dict[Text, Any],
               ) -> List[Dict]:
        # utter submit template
        msg = tracker.latest_message.get('text')
        print(msg)
        dispatcher.utter_template("utter_fallback_ticket_creado", tracker)
        return []

Domain:

 entities:
   - ticket
 slots:
   ticket:
     type: unfeaturized
     auto_fill: false
   requested_slot:
    type: unfeaturized
forms:
  - ticket_form

Thanks for the help!

@SpyrosCapetanopulos

If i’m not mistaking, this error occurred because the bot failed to recognize the ticket entity in the message. It should ask the user for the ticket slot again.

How do you define the nlu data for the ticket entity ? Can you run ‘rasa shell nlu’ in the command line and test if the entity is recognized by the bot ?

Hi @fuih ,

sorry for the delay in the response.

The entities is a Button as I show below:

  utter_fallback_2:
  - text: "Text!"
    buttons:
    - title: "Generar un Ticket"
      payload: '/GenerarTicket'

and in the intents I have it like this:

- GenerarTicket:
    use_entities: []

Please tell me if this is correct, or I need to do something else.

I’m going to prove the command you sent me for while.

Thank you!

The response of the command you sent me is as follows:

NLU model loaded. Type a message and press enter to parse it.
Next message:
/GenerarTicket
{
  "text": "/GenerarTicket",
  "intent": {
    "name": "GenerarTicket",
    "confidence": 1.0
  },
  "intent_ranking": [
    {
      "name": "GenerarTicket",
      "confidence": 1.0
    }
  ],
  "entities": []
}
Next message:

From what I understand, the entity is recognizing well.

Thank you!

@SpyrosCapetanopulos

"entities": []

This means no entity is recognized by the bot.

Secondly, the button’s payload is not an entity, it’s an intent. So when you push the button with payload “/GenerarTicket”, the bot understands that the user’s intent is “GenerarTicket” and response correspondingly. Therefore, the bot doesn’t receive any entity, hence the error.

You can set the slot with button by creating an intent like ‘inform_ticket’, then set the button’s payload as:

buttons:
- title: "Generar un Ticket"
  payload: '/inform_ticket{"ticket": "GenerarTicket"}'

Read furthermore about slots: Slots