This step-by-step guide describes the project and its source code for the conversion from the Trivia Quiz template to the Actions Builder platform.
The file structure for the project is comprised of the following directories, as described:
- converter: Sheets and locales conversion tool
- functions: Fulfillment webhook source code
- sdk: Action SDK resource files
Before you begin the migration, perform the following steps:
-
Install Node.js and NPM as follows:
- Install them with Node Version Manager (nvm) for Linux and Mac or nvm for Windows.
- The webhook runtime requires Node.js version 10 or higher.
-
Install the Firebase CLI as follows:
- Install it with MAJOR version 8. To do so, run the following command:
npm install -g firebase-tools@^8.0.0
. - Run
firebase login
with your Google account.
- Install it with MAJOR version 8. To do so, run the following command:
-
Install the Actions CLI as follows:
- Extract the package to a location of your choice and add the binary to your environment's PATH variable. Alternatively, extract the package to a location that's already in your PATH variable, such as
/usr/local/bin
. - Run
gactions login
with your Google account.
- Extract the package to a location of your choice and add the binary to your environment's PATH variable. Alternatively, extract the package to a location that's already in your PATH variable, such as
-
Go to Google Sheet Node.js Quickstart as follows:
- From that page, go to Step 1, and click Enable the Google Sheets API.
- Enter a project name or select the default name, "Quickstart", then click Next.
- Note: this project isn't the same as a new "Actions on Google" project needed for migration.
- For Configure your Oauth client, select Desktop app.
- Click Create.
- To download
credentials.json
, click Download client configuration. - Save the JSON file in the
converter/
directory.
Create a new project in Actions Console and upgrade the Firebase price plan as described here.
Perform the following steps:
- Go to Actions on Google Console.
- Select New project > Create project.
- Select What kind of Action do you want to build? > Game > Blank project.
To find your Project ID, go to Actions on Google Console for your project, and go to More ⋮ > Project settings > Project ID.
Note: Don't confuse the Project ID with the Project Name.
From the Firebase Console, select the same newly created project from Actions Console and upgrade its price plan to Blaze (pay as you go).
Caution: A Blaze plan is required for Cloud Functions for Node.js version 10 runtime.
Perform the steps described here.
To create a new Trivia Quiz action, make a copy of the Trivia Quiz sample sheet in your preferred locale-specific language. Update the sheet with your data. Alternatively, you can use your current Trivia Quiz data sheet. Refer to the following links to the Trivia Quiz sample sheets, in your preferred locale-specific language:
Open converter/config.js
and update the LOCALE_TO_SHEET_ID
mapping with your own Trivia Quiz data sheet ID for the specific locale you need to convert, as follows:
- Determine the Sheet ID, which is hard-coded as part of the sheet URL:
https://docs.google.com/spreadsheets/d/
<SHEET_ID>
/edit#gid=0
. - Uncomment the specific locales you need to convert.
- The sheet IDs provided in
converter/config.js
are the default sample sheets for each locale. To create a new Trivia Quiz action, make a copy of the sample sheet and update it with your own data. - Verify that the data sheet is owned by the same Google Account that performs the migration.
After you've updated the sheet ID, you have two options for how to proceed with the migration.
To automatically run all the migration steps, go to the root directory of the project, and run the following command: ./build.sh <PROJECT_ID>
. Be aware of the following guidance:
- When the script is run for the first time, it asks you to grant read access to your sheets. To do so, go to the URL it provides, accept read access, and copy the authorization code and enter it when prompted by the script.
- If you're taken to a warning page that says, "This app isn't verified," click Advanced. From the dropdown text that appears, click Go to Quickstart (unsafe) and continue the authorization process.
- If you encounter an issue, you can, instead, perform a manual migration steps.
To manually migrate the project, perform the steps described here:
- Run the sheet and locale conversion script
- Deploy the webhook to Cloud Functions for Firebase
- Use Actions CLI to push and preview your project
Perform the following steps:
- Go to the
converter/
directory. To do so, go to the root directory of the project and runcd converter
. - Run
npm install
. - Run
npm run convert -- --project_id <PROJECT_ID>
. Be aware of the following guidance:- When the script is run for the first time, it asks you to grant read access to your sheets. To do so, go to the URL it provides, accept read access, and copy the authorization code and enter it when prompted by the script.
- If you're taken to a warning page that says, "This app isn't verified," click Advanced. From the dropdown text that appears, click Go to Quickstart (unsafe) and continue the authorization process.
- After the conversion script completes, the parsed sheet data is added to the
functions/data/
directory, and the locale-specific data is added to thesdk/
directory.
Perform the following steps:
- Go to the
functions/
directory. To do so, go to the root directory of the project and runcd functions
. - Run
npm install
. - To deploy the "v1" webhook, run
firebase deploy --project <PROJECT_ID> --only functions:triviaQuiz_v1
. - After you release a version of the action, you can update your webhook and test your changes, so that you avoid an effect to your production action. To do so, go to the
functions/config.js
file, and update theFUNCTION_VERSION
value to an appropriate value such astriviaQuiz_v2
. This update deploys a new webhook URL, which reflects the updated value.
Perform the following steps:
- Go to the
sdk/
directory. To do so, go to the root directory of the project andcd sdk
. - To login to your Google account, run
gactions login
. - To push your project, run
gactions push
.- To fix the validation warnings, go to Actions Console, and from the Deploy section, update the missing directory information.
- If you need to sync the changes made in the Actions Builder Console with your local
sdk/
directory, rungactions pull
.
- To deploy the project to the preview environment, run
gactions deploy preview
.
You can test your action on any Google Assistant-enabled device that's signed into the same account used to create the project. You can also use the Actions on Google Console's simulator to test most features and preview on-device behavior.
If you encounter an issue or need additional information, refer to any of the following:
- If you have a question, the following forums are singificantly helpful:
- If you find any bugs, report them through GitHub.
- To learn more about Actions on Google, refer to Google Assistant's developer documentation.
- For guided, hands-on practice with Actions on Google, try some of the Codelabs for Google Assistant.
To contribute to this project, adhere to the steps described on the CONTRIBUTING.md page.
For more information on our license, read the LICENSE.