In a Rasa 2.8.0 bot, I have a form that takes two entities, job_type and job_name. Using some of what I’ve seen on this site, I’ve setting up a piece of code that reads from a csv file and presents a list of buttons for the user to click in order to set the slot value:
#button_form.py
from typing import Text, List, Any, Dict
from rasa_sdk import Tracker, FormValidationAction
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import EventType
import csv
class ActionButton(Action):
def name(self) -> Text:
return "action_button"
def run(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> List[EventType]:
csv_file = 'button_list.csv'
form_button_list = []
#read csv for button
with open(str(csv_file), 'rt') as f:
reader = csv.reader(f)
next(reader, None) # skip the headers
csv_output = {rows[0]:rows[1] for rows in reader}
logger.info(csv_output)
#generate button for raasa
for test_name in csv_output:
form_button_list.append({"title": test_name, "payload": test_name})
logger.info("form_button_list: "+str(form_button_list))
dispatcher.utter_message(text="Which value stream do you want to execute:", buttons=form_button_list)
return []
However, I not sure how to properly implement this in my rules file. Right now, it sits before the call to the active loop:
- rule: Activate conv_job_check
steps:
- intent: intent_job_check
- action: action_button
- action: form_job_check
- active_loop: form_job_check
- rule: Submit conv_job_check
condition:
- active_loop: form_job_check
steps:
- action: form_job_check
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: utter_job_check
- action: action_job_check
This ends up calling the button list for the first slot, job_type, but I end up needing to type in the value for the second slot, job_name. What it should do is present the buttons for each slot. I thought that I could put it into the loop itself, but that resulted in a training error.
Here is my domain file for reference. I understand I could set up the buttons in this, but I do not want to hard code them:
version: '2.0'
entities:
- job_name
- job_type
intents:
- intent_job_check
- intent_job_status
actions:
- utter_ask_job_name
- action_job_check
- utter_job_check
- utter_ask_test_type
- utter_ask_job_type
- action_button
responses:
utter_job_check:
- text: Checking jobs...
utter_ask_job_type:
- text: 'Please select a job type:'
utter_ask_job_name:
- text: 'Please select a job name:'
slots:
execute_action:
type: text
job_type:
type: text
job_name:
type: text
forms:
form_job_check:
job_type:
- type: from_text
intent_name: None
job_name:
- type: from_text
intent_name: None
What is the proper method for implementing these buttons for each slot?