Action_listen occurs only for the final question when the questions are asked in a loop in actions.py

Hi,

I am trying to implement a covid symptoms checker chatbot. The scenario is that I ask the user for his age and gender and make a REST call to a URL, which will give a list of questions to ask to the user. Each question has a question code. All the questions have a yes or no as an answer. I ask the questions to the user through Yes/No buttons and the answers to the questions are updated along with the question code and REST post call is done again to get the next set of questions. This process is repeated continuously till the finally the result is predicted. The questions keep changing based on the users answer to the previous question.

I am stuck at a point where once I get the list of questions, I loop through each question and ask the user through Yes/No buttons but when I run it in rasa interactive, action_listen occurs only for the final question in the loop and I am able to get the response of the last question only. I tried to force action_listen through FollowupAction(“action_listen”) but still, action listen occurs only for the final question in the loop.

Please find a pic of my actions.py file

I also tried the following code

When I tried the above code, action_listen was getting bypassed by action_symptom_check1. “action_symptom_check1” is the action in which the code is implemented. ini is a global variable. Since there can be multiple questions with each having Yes/No as an answer, I thought I will maintain only 1 slot and keep updating it for each Question.

If anyone has faced a similar issue, could you please suggest a workaround or if there is a completely different logic to be applied, then i am open to it as well. @Tobias_Wochinger Could you please help me out.

Regards,

Anand

Hi,

this sounds like a perfect use case for Forms . Have you checked them out?

Hi @Tobias_Wochinger,

Thanks for the suggestion. I am using forms to get the age and gender of the person and then using it to call the API. I am using a slot named num_of_ques to set the number of questions I need to ask the user based on the questions I get from the API.

I am stuck at how to keep the form active so that the form action is called recursively until all questions are asked since based on my understanding of the docs, atleast one slot has to be empty in the requested_slot method for the formaction to be called again. If I call the API in the submit function and get the number of questions and set the num_of ques slot, the formaction is not called again since all requested_slots are filled

Regards,

Anand.C

Hi @akelad, @JulianGerhard

Can any of you please help me?

Hey @anandtest94, the requested_slots list is what controls how many questions will be asked. I think the best way to handle this in your case would be to modify the requested_slots list dependent on what your API returns. Something like this:

@staticmethod
def required_slots(tracker) -> List[Text]:
   """A list of required slots that the form has to fill"""

   if tracker.get_slot('age') and tracker.get_slot('gender'):
     new_slot_list = api.call(...)
     return new_slot_list # you should probably still include the age/gender slots here as well
   else:
     return original_slot_list