Home

Awesome

<table> <tr> <td> This project is no longer actively maintained by the Google Creative Lab but remains here in a read-only Archive mode so that it can continue to assist developers that may find the examples helpful. We aren’t able to address all pull requests or bug reports but outstanding issues will remain in read-only mode for reference purposes. Also, please note that some of the dependencies may not be up to date and there hasn’t been any QA done in a while so your mileage may vary. <br><br> For more details on how Archiving affects Github repositories see <a href="https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-archiving-repositories">this documentation </a>. <br><br> <b>We welcome users to fork this repository</b> should there be more useful, community-driven efforts that can help continue what this project began. </td> </tr> </table>

Canvas Quiz

Canvas Quiz is a starter kit for developers to make custom, voice-enabled question-answer games for the Google Assistant. It uses Interactive Canvas, so you can create your own custom graphics and animations. Just deploy the code, put your questions and answers in a Google Sheet, and you’ll have your own quiz up and running.

This is not an official Google product. It’s just an experiment designed to help developers get started building with Interactive Canvas. If you want to learn more about Interactive Canvas, check out the official docs.

Setting up

Prerequisites: Node.js and npm. A bit of familiarity with Actions on Google and Interactive Canvas is helpful.

  1. Make a copy of the example Google Sheet.
  2. Create a new Firebase project.
  3. Enable Blaze billing (necessary to use Sheets API and Dialogflow API).
  4. Create a new Dialogflow project. When it asks you for your Google Cloud Project, choose the Firebase project you just created.
  5. Install the Firebase command line tools.
  6. Run npm run setup from the root of this repo. You'll need the gcloud command line tools installed. (MacOS/Linux only)

If you ran the setup command successfully, you can skip all the steps below!

  1. Run npm run installall to install npm packages for the frontend and backend.
  2. In Google Cloud Console, create a service account. Name it whatever you want.
  3. For the service account’s role, choose Project > Owner.
  4. Click “CREATE KEY”. Choose JSON. Click CREATE. This will download a json file.
  5. Move the file into deploy/functions/modules/auth.
  6. Share the spreadsheet with the email address you just created (needs view access)
  7. In the Google Cloud APIs library, find the “Google Sheets API” and enable it.
  8. Also find the "Dialogflow API" and make sure its enabled.
  9. In the (Dialogflow Console) [https://console.dialogflow.com] for your agent, click the gear icon in the upper left by your agent’s name. The click “Export and Import”.
  10. Click “RESTORE FROM ZIP”. Choose the file canvas-quiz-starter-agent.zip from the root of this repo. This will overwrite anything in this agent, and cannot be undone.
  11. Open deploy/functions/modules/config.js in an editor. Update these variables:
    • SERVICE_KEY should be the filename of the JSON key you downloaded.
    • CANVAS_URL should be your firebase hosting url + “/canvas”
    • AUDIO_URL should be where you want to store any sound effects (can use firebase hosting for this)
    • IMAGE_URL should be where you want to store any images (can use firebase hosting for this)
    • SHEET_ID should be the id of your Google Sheet. It's in the url: https://docs.google.com/spreadsheets/d/[ID_IS_HERE]/edit
  12. Open deploy/.firebaserc. Update $PROJECTID to your GCP project.

Building the frontend

npm run build will build the frontend into the deploy/public/canvas directory. npm run watch will watch for any changes and build automatically.

Deploying the frontend and backend

npm run deploy will deploy the frontend and backend to Firebase. It will also run a predeploy script that will parse the Google Sheet, update staticquiz.json, and update answer entities on Dialogflow.

Make sure to change your Dialogflow agent’s fulfillment URL to the URL of your cloud function.

Testing

Frontend The front end can be tested by running npm run frontend. The client/debug-helpers.js file exposes functions that simulate states sent from the backend, so you can see how the frontend looks and responds to backend changes by calling these functions from the console of your browser.

Backend The first time you want to run your action, go to your Dialogflow agent, and then click “See how it works in Google Assistant” in the right hand column. This will open the Actions on Google simulator.

In the Actions on Google console, go to Deploy > Additional Information. Set the category as “Games & Fun” and scroll down check the box labeled “Interactive Canvas”.

Styling the frontend

You can customize fonts, colors, spacing, and more in client/config.js. Make sure to build the frontend afterwards.

Working with the frontend

Frontend source files are in the client directory. They use LitElement to build HTML components.

Game.js is the primary controller that takes the state from the backend, sends data to components, and handles transitions.

Animations are handled using Greensock.

Working with the backend

Backend source files are in the deploy/functions directory. Index.js handles the main logic of the quiz.

Primary modules:

Publishing

In the Actions on Google console, go to Deploy > Additional Information. Set the category as “Games & Fun” and scroll down check the box labeled “Interactive Canvas”.

Less-obvious voice commands

These aren’t directly exposed to the user but could be useful for navigation or testing. If you don’t want them, delete the intents from the Dialogflow agent and delete the corresponding intent-handlers in deploy/functions/index.js.