Rasa Quiz Advice

I have a question regarding the best way to implement a feature into my rasa chatbot. I want the user to be able to select from different topics (such as animals, food etc). Then the chatbot asks questions on that certain topic and tests the users knowledge. After every question the chatbot either says if its right or wrong. I really would appreciate any tips or advice on the best way to tackle this. Thank you

1 Like

Hmmm not sure about the best way, but I can sketch a way out for you, and maybe you can iterate on it!

Selecting from different topics: The way to do this depends a bit on how many topics you have. I think it may be nice to do this with a button. That might look like the button below. Note that you will also have to store the information. I’d recommend a categorical slot.

  - text: "What topic would you like to be quizzed on?"
    - title: "animals"
      payload: '/inform{{"topic":"animals"}}'
    - title: "food"
      payload: '/inform{{"topic":"food"}}'

You’ll have to write a rule or story so that your system can ask utter_ask_topic at appropriate moments.

Chatbot asks questions on that certain topic & chatbot either says if its right or wrong: I think this one is best handled by a looping form and a custom action. You’ll need some way of keeping track of which questions have been asked (would use a slot for this as well, maybe just the index of the question to ask next, for example), and of course need to access the topic slot to see which question pool you’re pulling questions from. For each question, you’ll also need the correct answer.

      - type: from_text

You’ll need a custom action that sets the question slot with the initial question and combine that with a templated response (see below). This has to happen before you enter the form, because the form will try to fill the slot answer by asking utter_ask_answer.

  - text: '{question}'

You’ll gather the user’s response with the answer slot. In the validation action for this slot, you can check whether the user gave the right answer. Use the dispatcher to tell them whether they got it correct or not.

Since the slot for this form is now filled, you’ll have to write a rule to re-start the form. You should probably ask the user if they want to continue, to give them an option to break out of the form. If they do want to continue, start the process over.

1 Like

How to check whether the user got the correct answer is a whole other hairy topic :slight_smile: This will depend on how lenient you want to be, what questions you’re asking, and likely involves some entity extraction.

Thank you for the help. Really appreciate it!

1 Like

You’re welcome! Happy bot-building :rocket: