Dialogflow 13 – Multiple question questionnaire

Dialogflow 13 – Multiple question questionnaire

Hi,

This week I have been asked to create a questionnaire with several questions, that the user will be answering to then take actions based on the answers. In my case it was related to medical questions, but you could use this for anything.

In the agent we would use 3 intents, one that is starting the questionnaire, and 2 that will capture “Yes” or “No”. For the last 2 we will use an input context called “evaldata” to avoid triggering them outside of the questionnaire.

The mappings for the intents are as follows:

The function starting the questionnaire is the following one:

As you can see the current question is stored as a parameter within the context, and the answers are stored in an array that we initialize here.

When one of the Yes/No intents is triggered, they will call these functions:

As you can see the both use the same function, but passing the text as a parameter. The real function is this one:

The first thing that we do is reading the context and its parameters, then we store the Yes/No answer we have just received, and then we either jump to the next question, or we call the function to evaluate the results, which is done in the following function:

You would need to recode the conditions that apply to your questions. In this case we have 3 type of results, and what we do is to launch a followup intent using an event. You can read on how to use events in this post.

It would also be quite easy to store the answers in an external database, like we saw in this post about using BigQuery.

Finally, the constants that define the number of questions and their contents are defined at the beginning of th code:

I hope it is useful for you.

Regards

Jamarmu

============================================================

I work for Google Cloud, but this post are personal ideas and opinions

Leave a Reply