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.
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”
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?
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 []