This simple scenario implements a kids quiz game, where the bot asks questions one by one, and the user answers with yes or no. Bot replies if the answer is right and tells a short interesting fact about the question.

In this tutorial we will learn how to

use Google Sheets to store dynamic content for your scenarios
analyse user's replies and branch scenario depending on it
create and use custom entities
play short audio effects in bot's replies
connect a single scenario to both Amazon Alexa and Google Assistant

Please note that you can play with this scenario without building it. Just click on "Kids Quiz" template on a main page of Aimylogic to open a complete bot.



How this bot works

Once the user launches a bot, it offers the user to choose a quiz. For example, it may be Junior and Animals quizzes in the bot's database. Once the user made their choice, the bot fetches questions and answers of the selected quiz and start to ask questions one by one. The user replies with Yes or No answers. Bot informs the user about the right answer and provides a short interesting fact about the question. Once the list of question ends, the bot thanks the user and says goodbye.

Google Sheets as a content management system

For similar tasks it's better to store the content (list of questions and answers) separated from the scenario. Thus content managers can work with a content independently from the scenario's developer.

Google Sheets service enables you to create and manage your excel tables online. It's great tool to store some structured lists of data and then fetch it from anywhere.

Aimylogic provides an advanced tool to fetch arrays of rows from any published Google Sheet. Thus we can store or questions and answers in the Google Sheet and the bot can fetch it through an HTTP Request block once it needs this data.

Create a Google Sheet

There is a prepared template of the sheet where we stored two lists of questions-answers pairs for our quizzes.



Make a copy of this sheet on your Google Drive if you plan to manage it's data for your scenario

There are three columns in each list of this sheet.

Question column - the text of the question
Answer column - the right answer (yes or no)
Details column - some interesting fact

Each list represents an entire quiz. There are only two quizzes in this template - Junior and Animals. But you can create as many as you wish.

To use this sheet from your scenario you have to publish it to the web. Click on File - Publish to the web - Publish. Then copy an identifier of the sheet - you'll use it in your scenario to fetch the list of questions. You can find an identifier in the browser's address line. For example, an ID of this template is 1BQUOntmlQo2yXVkcarCWO72c__LXS2dOqYqX7qNjFFs

Create a scenario

Now you have to create a scenario in Aimylogic. Once a new bot is created, add a greeting text on a first screen, like this



If you are not familiar with Aimylogic's principles yet, please refer to the Quick Start article

Also add an Intents block with two intents - yes and no. If the user replies "yes", the bot should ask for a quiz to start. If no (or any other phrase) - the bot will say goodbye.

Add two regular buttons (Yes and No) to allow user to simply click on the button instead of using a voice.

The first screen

Create a custom entity

User can select one of quizzes that are stored in the Google Sheets. And if we create a bot that should understand a natural language, we have to train our bot to understand names of these quizzes. Aimylogic enables your bots to extract some useful data from the user's replies through Entities.

Click on Entities in the left menu and create a new dictionary with name quiz.



Here you have to add entities according the names of your lists in Google Sheet. In the Entity column write an ordinal number of a list in your Google Sheet, and in the Synonyms column provide as many synonyms for the quiz's name as you can. Click on Save Changes button and then return in scenario.

Select a quiz

Click on yes intent on the first screen to create a second one. Add here a text that invites a user to select one of two quizzes - junior or animals.



Then add an Intents block that recognises the user's choice.



Check Global intents checkbox to make this block available from anywhere in scenario. We need this to allow the user to start our future voice skill for Alexa and Google Assistant with a simple command like "Ask Kids Quiz to start Animals quiz".

Fetch quiz data

If the user replies with a quiz name, Aimylogic extracts it from the reply and creates a variable quiz with ordinal number of Google Sheet as value. Then it can be used to fetch a Google Sheet data through an HTTP request to the Google Sheets API.

Click on $quiz intent on the second screen and add HTTP Request block.

HTTP request settings

In the URL field provide an URL that looks like https://tools.aimylogic.com/api/googlesheet2json?sheet=${quiz}&id=1BQUOntmlQo2yXVkcarCWO72c__LXS2dOqYqX7qNjFFs

Replace an id parameter with your Google Sheet ID that you've copied in "Create a Google Sheet" step above

Add a variable questions that will store an entire array of rows of the selected list. Type $httpResponse as a value for this variable (httpResponse will contain a whole JSON response of HTTP response).

Note that we inserted a $quiz variable in the URL to fetch an array of rows from the list that was selected by the user

Start a quiz

Once the quiz data is fetched from the Google Sheet, the bot should inform the user that it's ready start and ask the first question.

Click on Success state in the HTTP Request block and add a Conditions block on the next screen. Here the bot checks if the questions array has items. Use first() function to fetch a very first item from a list of quiz questions. And click Save.



Click on this condition then to create a screen where the bot informs that it starts a quiz. Add a text block with text like "Cool! We are going to start a quiz! Listen my first question." Then add a Transition block to transit the bot to the next screen where it reads a question to the user

Reply with a short audio

Here you can see that the bot outputs some text for the user and generates some speech. This speech contains a short audio track before the current question text.

<audio src="https://tools.aimylogic.com/api/convert-audio?url=https://www.youtube.com/audiolibrary_download?vid=53c5c4e2db3fc403"/><p>$questions.current().question</p>

Parse user's reply

User can answer with Yes or No on every question of our quizzes. Then the bot should check if it's a right answer, generate an appropriate response and step forward to the next question in the questions array.

Add Intents block to the screen and create two intents - yes and no. Save the block and click on the yes intent. A new screen appears. Add here a Conditions block to check if the answer on the current question is yes.



Make the same for the no intent and create a Conditions block that compares the answer of the current question with "no".

Add two more screens that are connected to the right and wrong answers (else branch of each condition block). Inform the user if they are right or no with some text on that screens. This piece of scenario can look like this



Note that you can add multiple variants of an answer to each text block to randomise an output that the user will hear each time

Randomise bot&apos;s speech

Go to the next or end the quiz

Once the bot has informed the user about the right answer, it should go to the next question if there are some remaining items in the questions array. If there are no more items - it should say goodbye and end the quiz.

Add Transition block to each screen with right and wrong informer text and connect them with a new screen where the Condition block checks if there are some remaining items in questions variable. A special function next() will return a next item from an array.



If the condition is met - then the bot can say the user some speech like "Going to the next question!" and transit to the screen with yes and no intents where it reads a current question of a quiz. If there are no more questions in a quiz, an else branch of the Conditions block is firing and bot jumps to the screen with "Bye-bye" text. Add End of Scenario block to this screen to allow Alexa and Google Assistant to exit from your voice skill.

Test it!

Okay, we've created a first version of our quiz game! Not it's a time to test it. Click on the Test button on the top of scenario and try to go through a one of quizzes.

Test your bot

Create an Alexa skill

Let's try to connect your bot to the Amazon Alexa. Click on Channels menu item and then click on Alexa. Keep all settings as is and click on Connect button. Grant Aimylogic to manage your skills and go back to Aimylogic. Wait for a couple of minutes while Amazon builds your skill and then go to the Amazon Alexa test console or grab your Echo device. Invoke Alexa and say "Play Kids Quiz" to start your skill.

You can also say "Ask Kids Quiz to start Animals quiz" to start a particular quiz with a single phrase

Create a Google Assistant action

Now we are going to connect the same scenario to Google Assistant. Click on Google Assistant button in Channels section of Aimylogic. Keep everything as is and click on Connect. Click on Download action.json to download your action package. Then go through the steps described in Google Assistant article to connect your bot to the assistant.

Once you've done you can use any device with enabled Google Assistant to test your scenario.

As you can see Aimylogic enables you to use the same scenario to create skill for Alexa and action for Google Assistant

Conclusion

In this tutorial we learned how to create a single scenario for both Amazon Alexa and Google Assistant, how to use Google Sheets to separate content of scenario from the logic of scenario, how to use custom entities, branch the logic according the user's replies and insert audio tracks in the bot's responses.
Was this article helpful?
Thank you!