Google Assistant Trivia Game

Today we open sourced a trivia game app for the Google Assistant. The game is based on the template tool we announced in a previous post that turns your questions and answers into a fully functioning game.

The game works on your own Google Home, eligible Android phones, and the iPhone via the Google Assistant.

The open-sourced version of the game provides the same gameplay as the hosted template, but now you get to see the design and logic that makes it all work using Actions on Google, the development platform for the Google Assistant.

Resource Bundle

The open-source version of the trivia game comes with everything you need as a developer to host your own game and to customize the experience with your own features:

  • The API.AI agent that you can import into your own account to handle the game’s natural language understanding.
  • The fulfillment logic for the gameplay implemented as a Cloud Function for Firebase.
  • The prompts for 3 personas: teacher, regal queen and trivia bot. A total of 750 prompts have been designed by our VUI team to give each persona a distinct and fun personality. Find out how to create your own persona that complies with our design principles.
  • The prompts are categorized into 44 prompt types. Some of the types include welcome prompts, correct response prompts, help prompts, etc. During gameplay, prompts are selected from each appropriate type and then combined to provide a response to the user.
  • Audio tracks for each persona: introductory music, outgoing music, correct sounds, incorrect sounds, ding sounds, calculating sounds, and end-of-round sounds. In total, 43 audio tracks have been created by our sound designer in both OGG and WAV formats. The OGG versions comply with our audio loudness requirements for Assistant apps.

Under the Hood

The fulfillment logic for the trivia game is implemented as a Cloud Function for Firebase, which is the easiest way for you to deploy the game logic.

Note that Cloud Functions for Firebase provides a free tier without the need to provide payment information. This lets you get started with your own trivia game quickly and easily.

When the user invokes the app, the Assistant loads the app which then uses API.AI to handle user invocation as an intent. The intent invokes the fulfillment logic which is implemented in Cloud Functions for Firebase.

The game questions and answers are stored in a Firebase Realtime Database. The realtime database makes it very easy to use JSON data, especially since the fulfillment logic is implemented in Node.js and the Actions on Google client library supports Node.js too.

The fulfillment logic provides handlers for all the intents defined in the API.AI agent:

The app uses Firebase Hosting for the audio tracks of the game. During the gameplay the user responses are specified in SSML which supports embedding audio tracks.

Create Your Own Game

The questions and answers are loaded into the database using a Node.js script. Just edit the questions.json file for your game and run the script to upload the data to your Firebase database. You could also just load the default questions and then edit the database directly using the Firebase web GUI.

Then pick one of the personas; let’s go with the queen. Configure the selected persona in the fulfillment code and then the prompts will come from the queen’s set of prompt types. She will now say things like: “Behold! A victor!”, or “A valiant effort, but insubstantial.”

Create a project in the Actions Console and associate the project with API.AI. Now import the agent file so you can get all the intents needed for the gameplay.

You can now deploy the fulfillment logic using the Firebase CLI tool. You will be provided with the URL where the function is hosted.

Configure the API.AI agent fulfillment URL to point to your Cloud Function for Firebase. Use the Actions on Google integration option in API.AI to test your app in the web simulator.

Once you are happy with your game and want to share it with other users, submit it for review using the Actions Console.

Let the Games Begin

Now it’s super easy to create your own trivia game for the Google Assistant. You can try some of the published assistant games that have been built using this code: “Talk to American Presidents Quiz”, “Let’s talk to Seven of Nine Trivia”, or “Talk to Guess the Founder”.

Even if you don’t develop a trivia game, take as much of this design and resources for your own app. We can’t wait to see what great experiences you create for Actions on Google!

Former Google Assistant Developer Relations Engineer