Problem Statement:- I wanted to make other options visible and active after one option is selected, the list of option should remain visible and active , so that user can come back to chat and could be able to see and choose those option again if they wants to , i have created options through buttons and payload in domain.yml file in rasa.
Solution Tried But Didn’t Work:- I have tried
"keep_buttons_visible= true " (after payload command for all buttons options)
“disabled: false” (after payload command for all buttons options)
Tried below code by creating endpoints.py file addition with 2nd option
from rasa.shared.core.events import ButtonClicked
def button_clicked(event: ButtonClicked):
“”“This listener enables the option that was clicked, if it is not already enabled.”“”
option = event.data[“option”]
if option.get(“disabled”) is True:
option[“disabled”] = False
To make other options visible and active after one option is selected, you can use slot values to keep track of the selected option and enable/disable the buttons accordingly. Here’s a step-by-step solution: Define a slot in your domain.yml file to store the selected option:
slots:
selected_option:
type: text
Modify your button payloads to include the selected option as a slot value. For example:
utter_options:
title: “Option 2”
payload: “/select_option{"option": "option2"}”
Create an action in your actions.py file to handle the option selection and update the selected_option slot:
from typing import Any, Dict, List, Text
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict
class SelectOptionAction(Action):
def name(self) → Text:
return “action_select_option”
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> List[Dict[Text, Any]]:
option = tracker.get_slot("selected_option")
if option is not None:
dispatcher.utter_message(f"You selected: {option}")
# Enable/disable other options based on the selected option
if option == "option1":
dispatcher.utter_button_message(
"Other options:",
[
{"title": "Option 2", "payload": "/select_option{\"option\": \"option2\"}"},
{"title": "Option 3", "payload": "/select_option{\"option\": \"option3\"}"}
],
)
elif option == "option2":
dispatcher.utter_button_message(
"Other options:",
[
{"title": "Option 1", "payload": "/select_option{\"option\": \"option1\"}"},
{"title": "Option 3", "payload": "/select_option{\"option\": \"option3\"}"}
],
)
# Update the selected_option slot value
tracker.update_slot("selected_option", None)
return []
Add the action to your domain.yml file:
actions:
action_select_option
In your stories, make sure to include the story steps for option selection and handling the selected option. For example:
stories:
story: User selects an option
steps:
intent: select_option
entities:
option: “option1”
action: action_select_option
With this solution, when the user selects an option, the SelectOptionAction action will be triggered. It will handle the selected option, provide a response, AARPMedicare and enable/disable other options based on the selected option. The selected_option slot is updated to None after handling the selection, allowing the user to choose again if needed.
Handling buttons visibility via custom action isn’t a feasible option, as creating this many actions is very complicated.
Any other way to do will be appreciated
@stephens if you could help on this, please
I’m using rasa webchat widget, so any functionality that can help in keeping all the buttons visible and active even after selecting one option would really be helpful.
Thanks in advance.