This sample demonstrates Actions on Google user engagement features including daily updates and push notifications -- using Actions SDK in Node.js and deployed on Cloud Functions for Firebase.
After hearing a tip about developing Actions for the Google Assistant, users can subscribe to receive additional tips through notifications. There are two subscription options are available:
- If a category is selected, you are given the option to receive daily notifications at a fixed time; the notification deeplinks into receiving a tip from a category in a conversation.
- If the latest tip is selected, you are given the option to subscribe to notifications when a new tip is added; the notification deeplinks into receiving the newest tip in a conversation.
- Node.js and NPM
- We recommend installing using NVM
- Install the Firebase Functions CLI
- We recommend using version 6.5.0,
npm install -g firebase-tools@6.5.0
- Run
firebase login
with your Google account
- We recommend using version 6.5.0,
- Install the gactions CLI
- You may need to grant execute permission, ‘chmod +x ./gactions’
- From the Actions on Google Console, New project (this will become your Project ID) > Create project > under More options select Actions SDK > keep the Use Actions SDK to add Actions window open, will revisit in a later step.
- From the Cloud Platform console, find and select your Actions on Google Project ID
- From Menu ☰ > APIs & Services > Library > select Actions API > Enable
- Back under Menu ☰ > APIs & Services > Credentials > Create Credentials > Service Account Key.
- From the dropdown, select New Service Account
- name:
service-account
- role: Project/Owner
- key type: JSON > Create
- Your private JSON file will be downloaded to your local machine; save private key in
functions/
and rename toservice-account.json
- name:
- From the Firebase console, find and select your Actions on Google Project ID
- In the left navigation menu under Develop section > Database > Create database button > Select Start in test mode > Enable
- On your local machine, in the
functions
directory, runnpm install
- Run
firebase deploy --project {PROJECT_ID}
, replace {PROJECT_ID} to deploy the function - Update the action package,
action.json
, replacing the placeholder value withhttps://${REGION}-${PROJECT_ID}.cloudfunctions.net/aogTips
, obtained from the previous step.
Function URL (aogTips): https://${REGION}-${PROJECT_ID}.cloudfunctions.net/aogTips
- From the top level directory in this sample, run
gactions update --action_package action.json --project {PROJECT_ID}
with your Project ID. - In order to add the tips to the Firestore DB, in your browser, visit the following Function URL:
https://${REGION}-${PROJECT_ID}.cloudfunctions.net/restoreTipsDB
- In the Actions console, from the pop up window > select OK.
- From the top menu Develop > Actions (left nav)
- To setup Daily Updates:
- Select the
Tell a tip
intent > under User engagement > EnableWould you like to offer daily updates to users?
> add a titleAdvice Alert
> Save - Select the
Tell the latest tip
intent > under User engagement > EnableWould you like to send push notifications? If yes, user permission will be needed
> add a titleLatest Tip Alert
> Save
- Select the
- From the top menu click Test to open the Actions on Google simulator then say or type
Talk to my test app
. - To test daily updates, choose a category. Below the tip, the app will show a suggestion chip to subscribe for daily updates.
- To test push notifications, choose to hear the latest tip. Below the tip, the app will show a suggestion chip to subscribe for push notifications.
- Then add a new tip to the Firestore Database to trigger a notification to the subscribed users. In the tips collection > select Add document:
- Document ID: select Auto ID
- field:
category
, type: string, value:tools
- field:
created_at
, type: string, value:2019-05-30T011:00:00.000Z
and modify value to current time - field:
tip
, type: string, value:Here's the most recent info about tools
- field:
url
, type: string, value:https://developers.google.com/actions/assistant/updates/notifications
- You can test your Action on any Google Assistant-enabled device on which the Assistant is signed into the same account used to create this project. Just say or type, “OK Google, talk to my test app”.
- You can also use the Actions on Google Console simulator to test most features and preview on-device behavior.
- Questions? Go to StackOverflow, Assistant Developer Community on Reddit or Support.
- For bugs, please report an issue on Github.
- Getting started with Actions SDK Guide.
- Actions on Google Documentation
- Actions on Google Codelabs.
Please read and follow the steps in the CONTRIBUTING.md.
See LICENSE.
Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service.