Skip to content
This repository has been archived by the owner on Dec 24, 2021. It is now read-only.

IBM/watson-google-assistant

Repository files navigation

WARNING: This repository is no longer maintained ⚠️

This repository will not be updated. The repository will be kept available in read-only mode.

Create an Action for Google Assistant using Watson Assistant

This code pattern includes a Watson Assistant workspace to demonstrate an implementation of a retail agent that can ask for reservation schedules and specifics. To demonstrate how to test it with Google Assistant devices, we will setup a Google Action that calls out to our Node.js server which interacts with Watson Assistant.

When the reader has completed this code pattern, they will understand how to:

  • Create a Google Assistant Action
  • Create a Node.js Express web application
  • Deploy the Node.js app with Red Hat OpenShift or Cloud Foundry on IBM Cloud
  • Interact with Google Assistant and Watson Assistant
  • Use the conversation token to maintain the context
  • Leverage the content catalog for general, customer care, and bot control intents
  • Handle digressions during a conversation

architecture

Flow

  1. User talks or types to Google Assistant.
  2. Google Assistant posts text to an HTTPS endpoint.
  3. Node.js server calls Watson Assistant to get the response.
  4. The response is returned to Google Assistant.
  5. Google Assistant replies to the user.

Watch the Video

video

Steps

  1. Deploy the server

  2. Setup Google Actions

  3. Talk to it!

Deploy the server

Click on one of the options below for instructions on deploying the Node.js server.

openshift public

Setup Google Actions

  1. Go to Actions on Google Developer Console

  2. Create your project

    • Click on New project
    • Enter a project name
    • Choose the default language for your Actions
    • Select your country or region
    • Click on Create project
    • Click on the Actions SDK card
    • Click OK
  3. Set the invocation name

    • Under Quick setup, click Decide how your Action is invoked.
    • Enter a display name. Users will say or type this name to explicitly invoke your action.
    • Hit Save.
  4. Obtain your project ID

    • Click on the vertical 3 dots next to your account avatar and go to Project settings.
    • Save the Project ID to use later.
  5. Clone the repo

    Clone the watson-google-assistant repo locally. In a terminal, run:

    git clone https://github.com/IBM/watson-google-assistant
  6. Install the gactions CLI

    • Download the gactions CLI from here.
    • chmod the gactions file to make it executable.
    • Copy the gactions file into your local repo's actions directory.
      # For example, depending on your download and repo directories...
      
      chmod +x ~/Downloads/gactions
      cp ~/Downloads/gactions ~/watson-google-assistant/actions/
  7. Edit url in the actions/action.json file in your local repo.

    • If you deployed with OpenShift, use the URL you saved at the end of the OpenShift deployment (from a TLS secure Hostname).

    • If you deployed with Cloud Foundry, use your app URL.

    Note: The URL must have an https:// prefix!

  8. Create the action using the CLI

    Note: If/when it prompts you to enter an authorization code, browse to the provided URL to login and authorize the CLI to use your account and copy/paste the auth code at the prompt.

    • Run the gactions command to update your action and prepare it for testing. Use the project ID you saved earlier.

      cd ~/watson-google-assistant/actions/
      ./gactions update --action_package action.json --project <YOUR_PROJECT_ID>
      ./gactions test --action_package action.json --project <YOUR_PROJECT_ID>

Talk to it!

  1. Test it in the simulator

    • Go back to your Actions on Google Developer Console
    • Use the Test tab and start testing
    • Type in the Input box or click on the microphone icon to use voice input
    • Say "Talk to my test app" or "Talk to <your app name>" to initiate the conversation
  2. Try it with your phone, your Google Home, or other device

    • Log into the device with the same account you used to create your test app
    • Say "Hey Google, talk to <your app name>"
    • Alternatively, test the implicit invocation with "Hey Google, get me some wheels" or "Hey Google, rent a car"
  3. Chat and fill in the "slots" using natural language

  4. Try some "digressions" such as:

    • Positive or negative feedback
    • Ask to talk to the manager
    • Are you a human?
    • Do you know any jokes?
    • Store hours
    • Store locations
  5. If you want to submit the app for approval, follow Google's process documented here

Sample output

Testing with the simulator

Web Simulator

Troubleshooting

If you get an error on your Cloud Foundry deployment, please see this issue. You will need to add environmental variables to your CF app, and then once you do that, the app will restart automatically and it should work as intended.

License

This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.

Apache License FAQ