How to model while loop for QA bot

I want to do something like the following:

Bot: Want to answer some questions?
User: Yes
while continue:
   Bot: (fetches question from db and uses dispatcher.utter_message)
   User: (provides his answer)
   Bot: (stores answer)
   Bot: Want to answer another question?
   User: (provides his answer-> if intent affirm stay in loop; if intent deny leave loop) 
Bot: Thanks for your help!

I generally understand actions and formations but I can not bring them together for this loop. Can someone help me out?

I think my story should look like this:

- intent: something
- action utter_want_to_answer_questions
- intent: affirm
- action: action_ask_question_form
- active_loop: action_ask_question_form
- intent: deny
- action: action_deactivate_loop
- active_loop: null

How does the action_ask_question_form have to look like? I think I need two slots continue and answer but do I use the dispatcher in a form action and do I keep it running (setting continue to None after I have stored the answer in the db)?

1 Like

Hello @somebody , welcome to the Forum!

You can achieve this question-loop with rules. First, you’d write a rule ask_question -> inform -> store_answer -> ask_continue, then another rule for ask_continue -> yes -> ask_question. And also rules for the “no” option and one to start the loop.

The tricky thing here is that the intent of the user’s answer doesn’t matter. If you can group typical answers into one intent, then this is the way to go. Otherwise, you’ll need to either define a 1-slot form with a from_text setting, or list all possible intents in the rule using OR-statements.

2 Likes

Thanks for the quick response. I will give it a try!

Works Iike a charme. I solved it with 2 slots (one sets the other one to empty when the intent is affirm and sets its own value when the intent is deny). Thanks @j.mosig

1 Like