Hello everyone,
I have a spreadsheet. Each sheet corresponds to a specific user and consists of two columns. The first one has 5 questions and the other has answers. All the questions can be answered by a button or open answer. I don’t have any entity or slot for this.
Below is my custom action that I have implemented:
class ACTIVLIMquestionnaire(Action):
def name(self):
return "action_activlim_questionnaire"
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
user_id = next(tracker.get_latest_entity_values("number"), None)
current_day = datetime.datetime.today()
try:
workbook = load_workbook(filename=".\\activlim_q.xlsx")
except:
workbook = Workbook()
workbook.save(filename=".\\activlim_q.xlsx")
try:
worksheet = workbook[f"{user_id}"]
except:
worksheet = workbook.create_sheet(f"{user_id}")
worksheet["A1"] = "Questions"
worksheet["A2"] = "Could you, please, indicate how difficult you perceive walking more than one kilometer"
worksheet["A3"] = "Could you, please, indicate how difficult you perceive ringing a doorbell"
worksheet["A4"] = "Could you, please, indicate how difficult you perceive carrying a heavy load"
worksheet["A5"] = "Could you, please, indicate how difficult you perceive picking up something from the floor"
worksheet["B1"] = current_day
worksheet = workbook[f"{user_id}"]
position = 2
for value in worksheet.iter_rows(min_row=2, max_row=5, min_col=1, max_col=2, values_only=True):
dispatcher.utter_message(value[0], buttons= [
{"payload": "/inform", "title": "Impossible"},
{"payload": "/inform", "title": "Difficult"},
{"payload": "/inform", "title": "Easy"}
])
position += 1
if tracker.get_intent_of_latest_message == "inform":
worksheet[f"B{position}"] = tracker.latest_message["text"]
elif tracker.get_intent_of_latest_message == "deny":
workbook.save(filename=".\\activlim_q.xlsx")
dispatcher.utter_message(response="I will stop the process now.")
break
return []
My goal was to create something similar to a form loop but within the custom action (this is why I used the for
loop) but I didn’t work because what it does is to answer questions in a row and takes responses only for the last one.
I would like how could I approach this problem in a better way? I am thinking that it is not an issue that I should use rasa forms
to solve.
Regards