The questionnaire bot

So the bot is imaginary but the application is universal. In my project I want to ask the user some questions which have the same options. E.g. on a scale from 1 to 5. Do you agree with X, yes or no? The intents are the same, the entities are the same, but the context is different.

How can I store an entity depending on the last action of the bot? Right now my slot gets overwritten (obviously) since the entity is the same.

I hope I made myself clear :slight_smile:

1 Like

Yes perfectly clear :smiley: So the way to do this is to have slot names that are different to the entity and then store the entities in a slot in a custom action. So your stories would look something like this:

* ask_question1
  - inform{"scale":"1"}
  - action_store_response1
  - slot{"response1":"1"}
* ask_question2
  - inform{"scale":"4"}
  - action_store_response2
  - slot{"response2":"4"}

Does that make sense?


Hmm :face_with_raised_eyebrow: So I need to make a custom action for each question/slot?

Yes, they’re very small actions though, all they need to do is grab the entity and return a slot set event

I got it working, no sweat

1 Like

@Krogsager @akelad can you guys please share the example bot for reference it would be much helpful and appreciated

what kind of example bot?

the same questonaire bot. i want to create a survey bot where the answer would be plain text. how can i achieve that using rasa. Any help would be much appreciated. @akelad

Here is an example action I made to get Likert ratings. But notice that the custom actions syntax may have changed because this was done on an older version of Rasa.

The user is asked for, on a scale from 1-5 how bad something felt, mentally.

class ActionStoreLikertPsychological(Action):

    def name(self):
        return 'custom_act_likert_psychological' #This is used in the story

    def run(self, dispatcher, tracker, domain):

        dictData = next((e for e in tracker.latest_message.entities if
                                   e['entity'] == 'ent_likert'), None)
        rating = dictData['value']
            rating = int(rating)
            if (rating < 1) or (rating > 5):
                dispatcher.utter_message("I need a number between 1 og 5")
                return [SlotSet("slot_likert_psychological", None)]
                #dispatcher.utter_message("den psychological strain is set to " + str(rating))
                return [SlotSet("slot_likert_psychological", rating)]

            dispatcher.utter_message("I need a number between 1 and 5")
            return [SlotSet("slot_likert_psychological", None)]

Then you also need to train some intents with the entity being 1,2,3,4,5.

1 Like

Thanks @Krogsager for quick reply. i was just wondering for i don’t have a response like 1 to 5 and i would ask questions such as how was your experience with product, Is there anything that we can improve. questions like this whose response is open ended and it would be difficult to train the model on responses from user. I am a bit confused about how can i leverage rasa to do that and also i am a bit new to it.So if you have any idea on how could i achieve this it would be great help.

With any chat bot, you get the most benefit from it when you have you have to answer specific questions, or help a user through a precisely defined task. (E.g. FAQs, password reset, food ordering) There are no chatbot system today that can handle open ended conversations. If you are looking for sentiment analysis in long texts you could take a look at this watson api.

Is it possible to ask different questions depending on the user’s responses?

e.g. Q1 - yes or no?

if yes: Q1a

if no: Q2

Yes, that is the point of story trees.

can we set the whole response of a message as a slot

suppose i ask some question and whatever response i get i save it as a slot and then i ask another question. is this possible ???

I don’t think so. But you could build a custom action that does it for you.

like it asks multiple questions and stores user’s response. i am now wondering whether rasa is a good choice for such an application or should i use something else

Sure it can be done, but I wonder why you would do it. I concluded (when I made this thread) that it made more sense to use a normal questionnaire form instead of a chatbot. It is easier for the user to fill a form than chat with a bot.

Please don’t spam this post. Forms do exactly what you want, you can read about them here