IBM/alexa-skill-watson-conversation

Name: alexa-skill-watson-conversation

Owner: International Business Machines

Description: Alexa Skill using OpenWhisk, IBM Watson Assistant and Weather Channel Data

Created: 2017-06-29 06:52:47.0

Updated: 2018-04-20 05:22:38.0

Pushed: 2018-04-10 14:52:43.0

Homepage: https://developer.ibm.com/code/patterns/create-an-alexa-skill-with-serverless-and-a-conversation/

Size: 5274

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Create an Alexa skill using Watson Assistant and OpenWhisk

Watson Conversation is now Watson Assistant. Although some images in this code pattern may show the service as Watson Conversation, the steps and processes will still work.

In this Code Pattern, we will create an Alexa skill using Watson Assistant via the Apache OpenWhisk serverless framework. Alexa is the voice service behind products like the Amazon Echo. IBM Cloud Functions (based on Apache OpenWhisk) will be used to integrate Alexa with Watson Assistant. Credit goes to Niklas Heidloff for creating the original project.

An example conversation is included to demonstrate how to pass context between different intents. You can also use this Code Pattern to try out a conversation from the Bot Asset Exchange (BAE).

When the reader has completed this Code Pattern, they will understand how to:

Flow
  1. User says “Alexa, ask Watson…“.
  2. Alexa invokes IBM Cloud Functions with input text.
  3. The action gets the conversation context from Redis (if any).
  4. The action gets a response from Watson Assistant.
  5. The Weather Company Data service provides the forecast (when applicable).
  6. The response context is stored in Redis.
  7. The response text is sent back to Alexa.
  8. Alexa replies to the user.
Included components
Featured technologies

Watch the Video

Steps

Run locally
  1. Clone the repo
  2. Create a Watson Assistant workspace
  3. Create a Compose for Redis service
  4. Create a Weather Company Data service
  5. Configure credentials
  6. Create the OpenWhisk action
  7. Create an Alexa skill
  8. Talk to it
1. Clone the repo

Clone the alexa-skill-watson-conversation repo locally and cd to the local repo (for commands in later steps). In a terminal, run:

t clone https://github.com/IBM/alexa-skill-watson-conversation
 alexa-skill-watson-conversation
2. Create a Watson Assistant workspace

Sign up for IBM Cloud if you don't have an IBM Cloud account yet.

Use one or both of these options (with or without BAE) to setup a Assistant workspace.

Using Bot Asset Exchange (BAE)

If you are using BAE, use Get a bot and Get this bot to automatically create your Assistant service and import your workspace(s). The service will be named Bot Asset Exchange Workspaces and can hold up to 5 selected workspaces.

Using the provided workspace.json file

Create the service by following this link and hitting Create:

Import the Assistant workspace.json:

3. Create a Compose for Redis service

NOTE: The code currently requires you to disable TLS.

  1. Follow this link: Compose for Redis
  2. Use the TLS Enabled pull-down to select False
  3. Hit the Create button

4. Create a Weather Company Data service

If you are using the provided workspace.json, use Weather Company Data to provide weather responses.

Follow this link and hit Create:

This service includes an OpenWhisk package. Run the following to install the OpenWhisk bindings for IBM Cloud:

 plugin install Cloud-Functions -r Bluemix

Use bx login to initially login or to change your target:

ogin -a <API endpoint> -o <Organization> -s <Space> 

Run the following command to update your OpenWhisk bindings if they are already installed:

 wsk package refresh

Run the following to test OpenWhisk on IBM Cloud:

 wsk action invoke /whisk.system/utils/echo -p message hello --result
5. Configure credentials

The credentials for IBM Cloud services (Assistant, Compose for Redis and Weather Company Data), can be found in the Services menu in IBM Cloud, by selecting the Service Credentials option for each service.

Find the WORKSPACE_ID by clicking on the context menu of the workspace and select View details.

The default runtime parameters need to be set for the action. These can be set on the command-line or via the IBM Cloud UI. Here we've provided a params.sample file for you to copy and use with the -param-file .params option.

Copy the params.sample to .params.

 params.sample .params

Edit the .params file and add the required settings.

params.sample:

ONVERSATION_USERNAME": "<add_conversation_username>",
ONVERSATION_PASSWORD": "<add_conversation_password>",
ORKSPACE_ID": "<add_conversation_workspace_id>",
EDIS_URI": "<add_redis_uri>",
EATHER_URL": "<add_weather_url>"

6. Create the OpenWhisk action
Create the OpenWhisk action

Run these commands to gather Node.js requirements, zip the source files, and upload the zipped files to create a raw HTTP web action in OpenWhisk.

Note: You can use the same commands to update the action if you modify the code.

m install
 action.zip
p -r action.zip main.js package* node_modules
 wsk action update alexa-watson action.zip --kind nodejs:6 --web raw --param-file .params

Determine your IBM Cloud endpoint:

To find this URL, navigate to IBM Cloud Functions - Actions, click on your action and navigate to Endpoints. The Web Action URL ends with .json.

7. Create an Alexa skill

Sign up for an Amazon Developer Portal account here.

Go to https://developer.amazon.com/alexa/console/ask and click the Create Skill button.

Provide a name and hit Next.

Use the Select button to create a Custom skill and hit the Create Skill button.

Provide an invocation name:

Add a custom slot type:

Add a custom intent type:

Configure the endpoint (back in the Alexa Skills Console):

Hit Save Model and Build Model. Your skill is ready for testing!

8. Talk to it

Use the Test tab in the Amazon developer console, or you can run the sample via Alexa enabled devices, or the Echo simulator.

You can invite others to test it with the beta test feature. In order to be eligible for beta test, you must fill out most of the publishing information.

You probably shouldn't publish this example, but you are now ready to create and publish your own Alexa skill.

Sample output

Here is a sample conversation flow using the provided conversation workspace.json:

The sample has been implemented via the slots filling functionality in Watson Assistant. The screenshot shows how the entity (slot) 'location' is defined as mandatory and how the value is stored in a context variable.

alt text

The next screenshot shows how the location is automatically used in the next 'weather' intent.

alt text

Troubleshooting

Use the IBM Cloud UI to monitor logs, or use this command to show the latest activation log:

 wsk activation list -l1 | tail -n1 | cut -d ' ' -f1 | xargs bx wsk activation logs

Links

Learn more

License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.