How To Setup Google Assistant Trivia Game In Detail (Part 2)

Vortana Say
ProAndroidDev
Published in
5 min readJul 25, 2017

--

Welcome to “How To Setup Google Assistant Trivia Game In Detail” part 2. Here is the part 1 in case you miss it.

STEP II: Deploy the fulfillment Webhook provided in the functions folder using Google Cloud Functions for Firebase and the static resources needed by the project using Firebase Hosting:

  • Open the file functions/index.js and find the declaration of the HOSTING_URL constant at the top. Replace the ‘<YOUR_PROJECT_ID>’ placeholder with the Project ID of the Firebase project, that you can find in the general settings page of your project in the Firebase Console.

For instance, the final value of HOSTING_URL should look like https://mytriviagame-3772e.firebaseapp.com. (Note: your project ID can be different.)

What is Firebase CLI? It is a command-line interface for Firebase. In another word, it allows us to interact with firebase through command lines. Read more about Firebase CLI here and here.

Install Firebase CLI in your local machine (through Terminal for Mac and Command Prompt for Window):

npm install -g firebase-tools

Important note: before executing any other following commands, make sure you change directory (using cd <path> command) to the directory path that you just extracted (apiai-trivia-game-nodejs-master).

Login to Firebase:

firebase login

After allowing Firebase to collect anonymous CLI usage information, a web browser will automatically open a web page. Log in with the account that you use to create this project. Then this will appear.

Go back to Terminal or Command prompt, and run Firebase init command, then choose to configure Hosting and Functions. (Press tab to select and use arrow key to navigate).

firebase init

Select the project you’ve previously created in Actions on Google Console as the default project. In the configuration wizard, accept all the default choices provided by firebase init

The firebase init command will create a firebase.json setting file in the root of your project directory.

  • If you want to customized the database with your own questions and prompts, you can modified them in questions.json and prompts.json.
  • Generate a private key using Firebase Settings/Service Accounts, and edit functions/database.js file with the path to the JSON certificate file.

Edit database.js file with the correct path of the certificate file.

Add Firebase database name to database.js file.

Now populate the database with the command: node database.js

Note: make sure you navigate to function directory which has database.js file.

Then, you can verify if the database has been updated in your Firebase project.

  • Deploy the trivia game project to Firebase

Run Firebase deploy and take note of the endpoint where the fulfillment Webhook has been published. It should look like Function URL (triviaGame): https://us-central1-mytriviagame-3772e.cloudfunctions.net/triviaGame.

The command will also deploy the static assets at https://us-central1-mytriviagame-3772e.cloudfunctions.net/.

You can verify the deployment by going to Hosting, located in the left navigation menu in the Firebase console:

STEP III: Wire things together

  • Go back to the API.AI console and select Fulfillment from the left navigation menu. Enable Webhook, set the value of URL to the Function URL from the previous step, then click Save.

In case you forgot your function, don’t worry. You can go to your Firebase project and click on Functions from the left navigation menu.

STEP IV: TESTING

Just Kidding :) We are not going to write any unit tests. The goal here is to test our trivia game through the simulator in Actions on Google.

  • In the API.AI console, select Integrations from the left navigation menu and open the Settings menu for Actions on Google.
  • Click Test.
  • Click View to open the Actions on Google simulator.
  • Type : Talk to my test app in the simulator, or say OK Google, talk to my test app to any Actions on Google enabled device to signed into your developer account.

Voilà, now the setup for Trivia Game for Google assistant platform is completed. You can try out the game in the simulator.

Where to go from here

  • Customized Small Talk feature in API.AI

What happens if users type or say common questions/requests such as How are you? Who are you? etc. In API.AI, such questions can be customized in Small Talk. It is a module in API.AI console that can be found in the left navigation menu; It allows us to customized responses to the most popular request.

  • Test on devices

On a supported device, such as the Google Home or an Android phone, log into the device with the same account that you used to create your Actions on Google developer project.

(https://developers.google.com/actions/apiai/submit-app)

Finally, create your own trivia games and submit your app to Actions on Google for approval. Why not? :)

Recommend and share these articles to others if you find them helpful. Leave your opinion below!

--

--