actions-on-google / dialogflow-digital-goods-nodejs

Digital Purchase API sample (using Dialogflow) in Node.js
Apache License 2.0
8 stars 5 forks source link
digital-goods google-assistant-transactions

Actions on Google: Digital Goods Sample

This sample demonstrates Actions on Google features for use on Google Assistant including the Digital Purchase API -- using the Node.js client library and deployed on Cloud Functions for Firebase.

Setup Instructions

Prerequisites

  1. Node.js and NPM
    • We recommend installing using NVM
  2. Install the Firebase CLI
    • We recommend using version 6.5.0, npm install -g firebase-tools@6.5.0
    • Run firebase login with your Google account

Digital Goods Requirements

Configuration

Actions Console

  1. From the Actions on Google Console, New project > Create project > under More options > Conversational
  2. In the Actions console, from the top menu under Deploy > fill out Directory Information, where all of the information is required to run transactions (sandbox or otherwise) unless specifically noted as optional.
    • Additional information >
      • Do your Actions use the Digital Purchase API to perform transactions of digital goods? > Yes > Save.
  3. From the top menu under Deploy > Brand verification (left nav) > select </> to verify your website. Once the status is Connected then can connect an Android app.
  4. In the Google Play Developer Console > Development tools > Services & APIs > App Indexing from Google Search > Verify Website button. Once you've verified your site it will take up to 24hrs for Brand verification reflect this change in the Actions console, nonetheless move on to the next step.
  5. Back in the Actions console, from the top menu under Develop > Actions > Add your first action > BUILD (this will bring you to the Dialogflow console) > Select language and time zone > CREATE.
  6. In the Dialogflow console, go to Settings ⚙ > Export and Import > Restore from zip using the agent.zip in this sample's directory.

Service Account Authentication with JWT/OAuth 2.0

  1. In the Google Cloud Platform console, select your Project ID from the dropdown > Menu ☰ > APIs & Services > Library
  2. Select Actions API > Enable
  3. Under Menu ☰ > APIs & Services > Credentials > Create Credentials > Service Account Key.
  4. 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 as service-account.json in functions/

Firebase Deployment

  1. Replace 'PACKAGE_NAME' in functions/digital-goods-service.js with the package name of your Android app
  2. On your local machine, in the functions directory, run npm install
  3. Run firebase deploy --project {PROJECT_ID} to deploy the function
    • To find your Project ID: In Dialogflow console under Settings ⚙ > General tab > Project ID.

Dialogflow Console

  1. Return to the Dialogflow Console > select Fulfillment > Enable Webhook > Set URL to the Function URL that was returned after the deploy command > SAVE.
    Function URL (dialogflowFirebaseFulfillment): https://${REGION}-${PROJECT_ID}.cloudfunctions.net/dialogflowFirebaseFulfillment
  2. From the left navigation menu, click Integrations > Integration Settings under Google Assistant > Enable Auto-preview changes > Test to open the Actions on Google simulator then say or type Talk to my test app.

Running this Sample

References & Issues

Make Contributions

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Terms

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.