How to start the custom actions with buttons

Hi, For my requirement i need to start the chatbot with FAQ’s like below which opens with questions and buttons. I started adding custom actions and ran still it considers to provide first input as a user input. Please let me know there is any way to do it.

https://www.hdfcbank.com/

click on Ask Eva

You have to incorporate this behavior in the action: action_session_start

Therefore you have to overwrite its default behavior and create the action on your own.

I am newbie to the rasa…still i can’t get it

in actions.py:

class ActionSessionStart(Action): def name(self) -> Text: return “fraud_details_form”

@staticmethod
def fetch_slots(tracker: Tracker) -> List[EventType]:
    """Collect slots that contain the user's name and phone number."""

    slots = []
    for key in ("fraudtype"):
        value = tracker.get_slot(key)
        if value is not None:
            slots.append(SlotSet(key=key, value=value))
    return slots

async def run(
  self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]
) -> List[Dict[Text, Any]]:

    # the session should begin with a `session_started` event
    events = [SessionStarted()]

    # any slots that should be carried over should come after the
    # `session_started` event
    events.extend(self.fetch_slots(tracker))

    # an `action_listen` should be added at the end as a user message follows
    events.append(ActionExecuted("action_listen"))

    return events

class ActionSubmit(Action): def name(self) -> Text: return “action_submit”

def run(self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    dispatcher.utter_message(template="utter_ask_fraudtype", FraudType=tracker.get_slot("fraudtype"))

rules.yml:

  • rule: Activate form

    steps:

    - action: utter_ask_fraudtype
    
    - action: fraud_details_form
    
    - active_loop: fraud_details_form
    
    • rule: Submit form

      condition:

      • active_loop: fraud_details_form

      steps:

      • action: fraud_details_form

      • active_loop: null

      • slot_was_set:

        • requested_slot: null
      • action: action_submit

domain.yml: utter_ask_fraudtype: - text: “What type of fraud you are looking into?” buttons: - title: “internal” payload: “/fraud_internal” - title: “external” payload: “/fraud_external” template: utter_details_fraudtype

actions:

  • ActionSessionStart
  • action_submit

forms: fraud_details_form: fraud: - type: from_entity entity: fraudtype

nlu: - intent: fraud_external examples: | - Its an [external]{“entity”: “fraudtype”, “value”:“external”} - external{“entity”: “fraudtype”, “value”:“external”}

  • intent: fraud_internal examples: |
    • Its an [internal]{“entity”: “fraudtype”, “value”:“internal”}
    • internal{“entity”: “fraudtype”, “value”:“internal”}

Here i am trying to launch chatbot with message and button. Can you please help me how to fix this?

I think you might miss some of the following:

  • the custom session start action function name has to return “action_session_start”
  • In the domain you have to list the action “action_session_start” so that Rasa “knows” that you have created a new, custom version
  • Within your “actions.py” you have to create this new version of “action_session_start”
  • This “action_session_start” has to incorporate the code you want to perform in “ActionSubmit” So the line dispatcher.utter_message(template="utter_ask_fraudtype", FraudType=tracker.get_slot("fraudtype")) has to be part of the session start

As I understand it, this action should utter a text and provide some buttons to click. If you incorporate an action_listen then the user can also just write some text. So you have to cover several possibilities within your stories:

  • The user just selects one of the buttons
  • The user asks something about the buttons
  • The user asks something completely different

If it is absolutely necessary that the user chooses one of the buttons then there are probably better ways, but to be honest, in that case I do not kow the best solution, as I did not handle such a case on my own. Maybee you can use forms for that or can remove the action_listen or something like that

If you would like to get further suggestions, I would ask you to describe exactly what you want to achieve at the session start. Do you want to “force” the user to choose one of the buttons. Do you want to allow him to ask questions, before choosing?

Thanks Harloc for providing the help. I am forcing the user to use only buttons

Hi Herald,

Yes i want to ask question, it should have buttons with internal and external buttons than based on that button click it should get next question with buttons again. Please share any sample code that will be helpful. Thanks

Hi, I tried your option and example as well.I haven’t used button here but still i haven’t get action message as a start of the session.Plz guide me

In stories i have below stories:

  • story: happy_path

    steps:

    • action: action_start_session

    • action: find_facility_types

    • intent: inform

In domain i have below content responses:

action_start_session:

- text: "Hey! How are you?"

  buttons:

    - title: "great"

      payload: "/mood_great"

    - title: "super sad"

      payload: "/mood_sad"

actions:

  • action_start_session

class ActionStarSession(Action):

"""This action class allows to display buttons for each facility type

for the user to chose from to fill the facility_type entity slot."""

def name(self) -> Text:

    """Unique identifier of the action"""

    return 'action_start_session'

def run(

    self,

    dispatcher: CollectingDispatcher,

    tracker: Tracker,

    domain: Dict[Text, Any]

) -> List:

    dispatcher.utter_message(template='action_start_session')

    return []