Giter VIP home page Giter VIP logo

ibm / alexa-skill-watson-assistant Goto Github PK

View Code? Open in Web Editor NEW
76.0 20.0 105.0 11.75 MB

Alexa Skill using IBM Watson Assistant and IBM Cloud Functions

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

License: Apache License 2.0

JavaScript 100.00%
watson-conversation alexa-skill openwhisk-actions bae conversation-context conversation-service nodejs ibmcode watson-assistant

alexa-skill-watson-assistant's Introduction

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 Alexa skill using Watson Assistant and OpenWhisk

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. 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:

  • Create an OpenWhisk action in the IBM Cloud Functions serverless platform
  • Store a session's Watson Assistant context across events
  • Import a skill from the Bot Asset Exchange (BAE) or a JSON file
  • Invoke a skill with Watson using Node.js
  • Create an Alexa skill to reach tens of millions of customers

architecture.png

Flow

  1. User says "Alexa, ask Watson...".
  2. Alexa invokes IBM Cloud Functions with input text.
  3. The action gets a response from Watson Assistant.
  4. The response text is sent back to Alexa.
  5. Alexa replies to the user.

Watch the Video

Note: The video includes a demonstration with Weather data lookups and a Redis database for storing context. The current pattern has been simplified to use neither -- just a simple Watson Assistant skill with Alexa. The context is now stored in the Alexa session attributes.

video

Steps

Run locally

  1. Clone the repo
  2. Create a Watson Assistant skill
  3. Configure credentials
  4. Create the OpenWhisk action
  5. Create an Alexa skill
  6. Talk to it

1. Clone the repo

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

git clone https://github.com/IBM/alexa-skill-watson-assistant
cd alexa-skill-watson-assistant

2. Create a Watson Assistant skill

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 an Assistant skill.

Using Bot Asset Exchange (BAE)

If you are using BAE, click on a Deploy this bot button to automatically create your Assistant service and import your skill. The service will be named Bot Asset Exchange Workspaces and can hold up to 5 selected skills.

Using the provided rent_a_car.json file

Create the service by following this link and hitting Create:

Import the Assistant rent_a_car.json:

  • Find the Assistant service in your IBM Cloud Dashboard.
  • Click on the service and then click on Launch Watson Assistant.
  • Go to the Skills tab.
  • Click Create skill
  • Click the Import skill tab.
  • Click Choose JSON file, go to your cloned repo dir, and Open the rent_a_car.json file in data/assistant/rent_a_car.json.
  • Click Import.

To find the SKILL_ID for Watson Assistant:

  • Go back to the Skills tab.
  • Find the card for the workspace you would like to use. Look for rent-a-car, if you uploaded rent_a_car.json. The name will vary if you used BAE.
  • Click on the three dots in the upper right-hand corner of the card and select View API Details.
  • Copy the Skill ID GUID. Save it for the .params file in Step 5.

view_api_details

3. Configure credentials

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 (which is used in the instructions below).

Copy the params.sample to .params.

cp params.sample .params

Edit the .params file and add the required settings as described below.

params.sample:

{
  "ASSISTANT_APIKEY": "<add_assistant_apikey>",
  "ASSISTANT_URL": "<add_assistant_url>",
  "SKILL_ID": "<add_assistant_skill_id>",
}

Finding the credentials

The credentials for IBM Cloud services can be found in the IBM Cloud UI.

  • Go to your IBM Cloud Dashboard.
  • Find your Assistant service in the Services list.
  • Click on the service name.
  • Manage should be selected in the sidebar.
  • Use the copy icons to copy the API Key and URL and paste them into your .params file.
  • For SKILL_ID, use the Skill ID for Watson Assistant from Step 2.

4. Create the OpenWhisk action

As a prerequisite, install the Cloud Functions (IBM Cloud OpenWhisk) CLI

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 or the .params.

npm install
rm action.zip
zip -r action.zip main.js package* node_modules
ibmcloud wsk action update alexa-watson action.zip --kind nodejs:default --web raw --param-file .params

Determine your IBM Cloud endpoint

To find this URL, navigate to IBM Cloud Functions - Actions, click on your alexa-watson action and use the sidebar to navigate to Endpoints.

functions_endpoints

5. 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.

create_alexa_skill

Provide a name, choose Custom model and hit the Create skill button.

select_custom_skill

Select the Start from scratch template and hit the Choose button.

select_template

Provide an invocation name:

invocation_name_v1

Add a custom slot type:

  • In the left sidebar menu, click on Slot Types (#) and hit + Add.

slot_types

  • Use the name BAG_OF_WORDS and hit the Create custom slot type button.

create_slot_type

  • Now BAG_OF_WORDS needs a slot value. Just enter Hello World and hit the plus sign so that it has a slot value.

bag_of_words

Add a custom intent type:

  • In the left sidebar menu, click on Intents (#) and hit + Add.

intents

  • Use the name EveryThingIntent and hit the Create custom intent button.
  • Add {EveryThingSlot} under Sample Utterances. Use the plus sign to create the EveryThingSlot.

sample_utterance

  • Scroll down to Intent Slots (#)
  • Use the Select a slot type pulldown to give EveryThingSlot the slot type BAG_OF_WORDS.

create_everything_intent

Click on Save Model and then Build Model.

save_and_build

Configure the endpoint:

  • Click on Endpoint in the sidebar.
  • Select HTTPS as the Service Endpoint Type.
  • For the Default Region enter the HTTPS service endpoint which is the URL of your OpenWhisk Web Action from step 6.
  • Add a .json suffix to your service endpoint.
  • Use the pull-down to select My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority.
  • Click the Save Endpoints button!

service_endpoint_type

6. Talk to it

Use the Test tab in the Amazon developer console.

Use the drop-down to enable your skill for testing in Development. You can type or talk and test the skill in the test UI.

Once enabled, 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 Watson Assistant rent_a_car.json:

sample_conversation

Troubleshooting

  • Want to see debug logging

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

    ibmcloud wsk activation list -l1 | tail -n1 | cut -d ' ' -f1 | xargs ibmcloud wsk activation logs
  • Testing invoke from CLI

    Use these commands to invoke the action (named alexa-watson in the example) without any input, then check the latest logs. Expect an error ("Must be called from Alexa").

    ibmcloud wsk action invoke alexa-watson -bvd
    ibmcloud wsk activation list -l1 | tail -n1 | cut -d ' ' -f1 | xargs ibmcloud wsk activation logs

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

alexa-skill-watson-assistant's People

Contributors

dependabot[bot] avatar dolph avatar hickeyma avatar imgbot[bot] avatar imgbotapp avatar kant avatar ljbennett62 avatar markstur avatar nheidloff avatar rhagarty avatar scottdangelo avatar stevemar avatar stevemart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alexa-skill-watson-assistant's Issues

Weather credentials

Hi,

I got the code running and working perfectly, the only issue is with weather... Although the intent work and is recognized, when the request to get the weather is launched, it gives me a timeout. I guess that probably is because the credentials on the .params for the weather service is not correct.

According the instructions I only need to insert there a WEATHER_URL... I did something similar "WEATHER_URL": "https://7940047a-f00c-4221-b46d-XXXXXXX:[email protected]" is that correct ?

Resource not found

I've followed your guide and I am using the system without the Redis database.
Then, my .params consists of:
{
"ASSISTANT_IAM_APIKEY": "",
"ASSISTANT_IAM_URL": "
",
"WORKSPACE_ID": "",
"WEATHER_URL": "
"
}

I've double checked all those parameters and they're okay. However, when I am calling the Watson Assistant skill by typing "Ask weather channel what do you know about me" it returns "There was a problem with the requested skill's response". If try the same in the Watson Assistant try out, everything works fine. The endpoint to IBM Cloud Action is correctly inserted into the Amazon Developer Console.
By inspecting the log from the IBM Cloud Functions, this is what I get:

"logs": [
"2019-08-20T20:00:52.308924Z stdout: Begin action",
"2019-08-20T20:00:52.308940Z stdout: Alexa attributes:",
"2019-08-20T20:00:52.308944Z stdout: undefined",
"2019-08-20T20:00:52.313028Z stdout: Connected to Watson Assistant",
"2019-08-20T20:00:52.313038Z stdout: Missing REDIS_URI Will use session attributes instead of Redis.",
"2019-08-20T20:00:52.313042Z stdout: Alexa sessionId: amzn1.echo-api.session.96d29f76-16a7-42fb-969f-2a56c365446f",
"2019-08-20T20:00:52.313045Z stdout: WORKSPACE_ID: c9d171f0-fef7-4a06-b338-0cab3d62b023",
"2019-08-20T20:00:52.313047Z stdout: Input text: start skill",
"2019-08-20T20:00:53.407930Z stderr: { Not Found: Resource not found",
"2019-08-20T20:00:53.407971Z stderr: at RequestWrapper.formatError (/nodejsAction/6mYD7bOa/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:218:21)",
"2019-08-20T20:00:53.407975Z stderr: at /nodejsAction/6mYD7bOa/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:206:29",
"2019-08-20T20:00:53.407978Z stderr: at ",
"2019-08-20T20:00:53.407980Z stderr: at process._tickCallback (internal/process/next_tick.js:189:7)",
"2019-08-20T20:00:53.407983Z stderr: name: 'Not Found',",
"2019-08-20T20:00:53.407986Z stderr: code: 404,",
"2019-08-20T20:00:53.407989Z stderr: message: 'Resource not found',",
"2019-08-20T20:00:53.407991Z stderr: body: '{"error":"Resource not found","code":404}',",
"2019-08-20T20:00:53.407994Z stderr: headers:",
"2019-08-20T20:00:53.407997Z stderr: { 'content-type': 'application/json; charset=utf-8',",
"2019-08-20T20:00:53.408000Z stderr: 'content-length': '41',",
"2019-08-20T20:00:53.408003Z stderr: 'access-control-allow-origin': '*',",
"2019-08-20T20:00:53.408005Z stderr: 'access-control-allow-methods': 'GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS',",
"2019-08-20T20:00:53.408008Z stderr: 'access-control-allow-headers': 'Content-Type, Content-Length, Authorization, X-Watson-Authorization-Token, X-WDC-PL-OPT-OUT, X-Watson-UserInfo, X-Watson-Learning-Opt-Out, X-Watson-Metadata',",
"2019-08-20T20:00:53.408011Z stderr: 'access-control-max-age': '3600',",
"2019-08-20T20:00:53.408014Z stderr: 'content-security-policy': 'default-src \'none\'',",
"2019-08-20T20:00:53.408016Z stderr: 'x-dns-prefetch-control': 'off',",
"2019-08-20T20:00:53.408019Z stderr: 'x-frame-options': 'SAMEORIGIN',",
"2019-08-20T20:00:53.408021Z stderr: 'strict-transport-security': 'max-age=15552000; includeSubDomains',",
"2019-08-20T20:00:53.408037Z stderr: 'x-download-options': 'noopen',",
"2019-08-20T20:00:53.408040Z stderr: 'x-content-type-options': 'nosniff',",
"2019-08-20T20:00:53.408042Z stderr: 'x-xss-protection': '1; mode=block',",
"2019-08-20T20:00:53.408045Z stderr: 'x-global-transaction-id': '134256d06524db272f02ad85861aa9f2',",
"2019-08-20T20:00:53.408048Z stderr: 'x-dp-watson-tran-id': '134256d06524db272f02ad85861aa9f2',",
"2019-08-20T20:00:53.408050Z stderr: 'x-edgeconnect-midmile-rtt': '88',",
"2019-08-20T20:00:53.408053Z stderr: 'x-edgeconnect-origin-mex-latency': '112',",
"2019-08-20T20:00:53.408056Z stderr: date: 'Tue, 20 Aug 2019 20:00:53 GMT',",
"2019-08-20T20:00:53.408058Z stderr: connection: 'close' } }",
"2019-08-20T20:00:53.408061Z stderr: Caught error:",
"2019-08-20T20:00:53.408082Z stdout: Error: Error talking to Watson.",

PS: I've already seen issue #39 which seems related to mine.

stderr: { Error: Resource not found

what is the problem ?

/alexa-skill-watson-conversation# bx wsk activation list -l1 | tail -n1 | cut -d ' ' -f1 | xargs bx wsk activation logs
2018-10-16T13:27:01.873285435Z stdout: Begin action
2018-10-16T13:27:02.082137332Z stdout: Connected to Watson Conversation
2018-10-16T13:27:02.088706799Z stdout: Connected to Redis
2018-10-16T13:27:02.088730783Z stdout: sessionId: amzn1.echo-api.session.0fa3d3b2-a69b-4a3c-8a43-4578bf8ba8d4
2018-10-16T13:27:02.102072117Z stdout: context:
2018-10-16T13:27:02.103601573Z stdout: {}
2018-10-16T13:27:02.103946337Z stdout: WORKSPACE_ID: 6bd637f6-1074-4d94-855e-d0d86f4f7b75
2018-10-16T13:27:02.103955002Z stdout: Input text: hi
2018-10-16T13:27:02.463362996Z stderr: { Error: Resource not found
2018-10-16T13:27:02.46341617Z stderr: at Request._callback (/nodejsAction/NjP0Z1G0/node_modules/watson-developer-cloud/lib/requestwrapper.js:102:21)
2018-10-16T13:27:02.463428631Z stderr: at Request.self.callback (/nodejsAction/NjP0Z1G0/node_modules/watson-developer-cloud/node_modules/request/request.js:185:22)
2018-10-16T13:27:02.463435974Z stderr: at emitTwo (events.js:106:13)
2018-10-16T13:27:02.463442117Z stderr: at Request.emit (events.js:191:7)
2018-10-16T13:27:02.463448427Z stderr: at Request. (/nodejsAction/NjP0Z1G0/node_modules/watson-developer-cloud/node_modules/request/request.js:1157:10)
2018-10-16T13:27:02.463456288Z stderr: at emitOne (events.js:96:13)
2018-10-16T13:27:02.463462308Z stderr: at Request.emit (events.js:188:7)
2018-10-16T13:27:02.463466539Z stderr: at Gunzip. (/nodejsAction/NjP0Z1G0/node_modules/watson-developer-cloud/node_modules/request/request.js:1079:12)
2018-10-16T13:27:02.463471236Z stderr: at Gunzip.g (events.js:292:16)
2018-10-16T13:27:02.46347533Z stderr: at emitNone (events.js:91:20)
2018-10-16T13:27:02.4634792Z stderr: code: 404,
2018-10-16T13:27:02.463483373Z stderr: error: 'Resource not found',
2018-10-16T13:27:02.463487402Z stderr: 'x-global-transaction-id': '7ecac92c5bc5e72640cc905f' }
2018-10-16T13:27:02.463684232Z stderr: Caught error:
2018-10-16T13:27:02.463817132Z stdout: Error talking to Watson.

I am unable to reach the requested skill

I did the steps as shown in the video and my alexa skill was working fine with my watson assistant. But then suddenly It does not work anymore. If I launch my alexa skill i get the response "I am unable to reach the requested skill". The Endpoint URL is correct as well as the SSL Certificate Type. I didnt change anything but suddenly it doesnt work but used to work fine before.

Thanks

Changes to the Bluemix Interface

Hi,

Just a small one, but the Bluemix interface has now changed so the webcall url is provided on the Bluemix screen under the HTTP option, and you do not have to reconstruct it from the REST url, using sed.

You could just change your screen shot like the one below, and delete the bit about constructing the url.
image

hardcoded Bluemix_Weather needs to be changed if you use a different name

My cloud function did not work initially, and it took me a while to debug and figured it out!
It turns out i used a different name for weather data service, and needed to change your main.js file below..

//if (result.name.startsWith('Bluemix_Weather Company Data'))
{ if (result.name.startsWith('Bluemix_2d-Weather Company Data')) {

I am happy now that this is working. Your video definitely helped a lot !

Resource not found

Hello,
I followed the guide as is.
https://github.com/IBM/alexa-skill-watson-assistant
When I am calling the Watson Assistant skill , it returns "There was a problem with the requested skill's response".
The only thing different so far is to put the URL as this message was and add the parameter "WORKSPACE_ID", What else should I modify?, Thanks :)

TLS=True does not work: Redis ECONNRESET and "rediss" warning

Redis is complaining about "rediss" -- that is only a warning and probably not the error, but then there is an ECONNRESET. So for some reason we are not able to maintain a connection to work with Redis.

             {"error":"The action did not produce a valid response and exited unexpectedly."},
              "success":false,
              "status":"action developer error"},
              "end":1520863837705,
              "logs":[
              "2018-03-12T14:10:37.299684781Z stdout: Begin action",
              "2018-03-12T14:10:37.636605477Z stdout: Connected to Watson Conversation",
              "2018-03-12T14:10:37.640980509Z stderr: node_redis: WARNING: You passed \"rediss\" as protocol instead of the \"redis\" protocol!",
              "2018-03-12T14:10:37.644396496Z stdout: Connected to Redis",
              "2018-03-12T14:10:37.644415148Z stdout: sessionId: SessionId.bbda3171-5438-4d2b-baff-1e9210cce63b",
              "2018-03-12T14:10:37.692747814Z stderr: events.js:160",
              "2018-03-12T14:10:37.69276912Z  stderr: throw er; // Unhandled 'error' event",
              "2018-03-12T14:10:37.692781985Z stderr: ^",
              "2018-03-12T14:10:37.692795232Z stderr: ",
              "2018-03-12T14:10:37.692802114Z stderr: Error: Redis connection to portal1213-8.bmix-dal-yp-06298201-d5d6-4bf3-9ab3-5b9a4d8ec887.thomas-suedbroecker-de-ibm-com.composedb.com:37151 failed - read ECONNRESET",
              "2018-03-12T14:10:37.692811179Z stderr: at exports._errnoException (util.js:1020:11)",
              "2018-03-12T14:10:37.692817643Z stderr: at TCP.onread (net.js:568:26)",
              "2018-03-12T14:10:52.134Z       stderr: There was an issue while collecting your logs. Data might be missing."

Effective immediately, we are announcing the retirement of our Weather Company Data for IBM Cloud service and will no longer accept new account registrations through the IBM Cloud Catalog.

https://www.ibm.com/cloud/blog/announcements/important-changes-related-to-weather-company-data-for-ibm-cloud

This code pattern was designed to work with other Watson Assistant dialogs, so it should still be good as an Alexa-to-Watson example, but it needs some cleanup to remove things that suggest there is a Weather service to invoke.

the workspace.json only uses the German locations, not sys-location

The beta sys-location feature allows the conversation to recognize many locations. The conversation also has a short list from a Germany example.

Somehow the exported json does not include the sys-location feature that was in the demo/video.

Now it works with either.

Changes to Alexa Interface

Hi,
Alexa have changed their interface and json schema specification, and so your original intent_schem.json file no longer works.

It turns out they have made a decision to have three default (system) intents Cancel, Stop and Help, on top of whatever we build.

This means the json should look something like the attached example. (We
think)
Alexa_intent_Schemav2.txt

Anyway, check it out

Redis

Hey nehidloff! Firstly i would like to thank you for this tutorial! thumbs up for that. I kinda get everything and all the steps you have mentioned thus far other than the part on redis and openwhisk.

  1. Watson Side i get it till the import conversation.
  2. However i know i need to create openwhisk grab that URL and paste it at amazon side. This is the part that i don't get. Could you explain how i could set up openwhisk / redis. From what i see so far, i need to pay for it. Is there no free version? if using the docker is free then where do i get the IPaddress and port number from?
  3. Alexa Side i get it.

Error: Unable to create action 'alexa-watson'

Screenshot from 2019-10-10 19-57-06

Hi there!
I'm facing an error while running the last step in creating the OpenWhisk action as shown in the attachment. I've double checked my Assistant API Key, Assistant URL, Workspace ID and Weather URL as well. Please help!

Best,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.