Skip to content

digideskweb/dialogflow-transactions-nodejs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Actions on Google: Transactions Sample

This sample shows everything you need to facilitate transactions for your Action in Node.js, including:

  • Check for transaction requirements
  • Get the delivery address
  • Confirm the transaction
  • Examples of Google Pay and merchant-managed payment options
  • Asynchronously update order status at any time (via order-update.js)

Setup Instructions

Action Configuration

  1. From the Actions on Google Console, add a new project (this will become your Project ID) > Create Project > under More options > Conversational
  2. In order to test out a transactions-based sample the following info must be provided. In the Actions console, from the left navigation menu under Deploy > Directory Information >
  • Images > add a small logo image
  • Contact details > add Developer email
  • Privacy and consent > add link to Privacy Policy
  • Additional information >
    • Select a Category
    • Do your Actions use the Transactions API to perform transactions of physical goods? > Yes > Save.
  1. From the left navigation menu under Build > Actions > Add Your First Action > BUILD (this will bring you to the Dialogflow console) > Select language and time zone > CREATE.
  2. In Dialogflow, go to Settings ⚙ > Export and Import > Restore from zip.
    • Follow the directions to restore from the agent.zip file in this repo.

Firebase Deployment & Webhook Configuration

  1. Install Firebase CLI
    • npm install -g firebase-tools
  2. Firebase SDK for Cloud Functions
    • firebase login
    • cd functions/
    • npm install
    • firebase init functions
      • What language would you like to write Cloud Functions > JavaScript
      • File functions/package.json already exists. Overwrite? > No
      • File functions/index.js already exists. Overwrite? > No
    • firebase deploy
  3. Copy the endpoint where the fulfillment webhook has been published:
Function URL (webhook): https://<REGION>-<PROJECT_ID>.cloudfunctions.net/webhook
  1. In Dialogflow Console > Fulfullment > Enable Webhook > Set URL to the Function URL that was returned after the deploy command > SAVE.

Testing this Sample

  1. From a mobile device > Assistant app > Personal Info > Payments > Set up a payment method for your Google account associated with this project.
  2. In the Dialogflow console, from the left navigation menu > Integrations > Integration Settings under Google Assistant > Enable Auto-preview changes > Test to open the Actions on Google simulator OR
  1. From the Simulator, ensure that you are testing in Development Sandbox: Enabled mode
  2. Type Talk to my test app in the simulator, or say OK Google, talk to my test app to Google Assistant on a mobile device associated with your Action's account.

Order Update Configuration (order-update.js)

  1. From the Dialogflow's console > go to Settings ⚙ and under the General tab > go the Project Id link, which will take you to the Google Cloud Platform console
  2. In the Cloud console, go to Menu ☰ > APIs & Services > Library
  3. Select Actions API > Enable
  4. Under Menu ☰ > APIs & Services > Credentials > Create Credentials > Service Account Key.
  5. 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
  6. In order-update.js, insert the file path to your key.
  7. In order-update.js, replace the <UNIQUE_ORDER_ID> placeholder string assigned to actionOrderId with the ID of the order you wish to update.
    • Similarly, ensure that the variable UNIQUE_ORDER_ID matches between index.js and order-update.js
  8. Run the script to send an order update by opening a terminal and running the following command: node order-update.js.

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.

About

A sample of the Transactions API in Actions on Google

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%