# WARNING: This repository is no longer maintained :warning:
> 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](https://www.ibm.com/watson/ai-assistant/)
via the [Apache OpenWhisk](https://openwhisk.incubator.apache.org/) 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](http://heidloff.net/) 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)](https://developer.ibm.com/code/exchanges/bots/).
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](doc/source/images/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](https://img.youtube.com/vi/_iODArA1Eqs/0.jpg)](https://www.youtube.com/watch?v=_iODArA1Eqs)
# Steps
## Run locally
1. [Clone the repo](#1-clone-the-repo)
1. [Create a Watson Assistant skill](#2-create-a-watson-assistant-skill)
1. [Configure credentials](#3-configure-credentials)
1. [Create the OpenWhisk action](#4-create-the-openwhisk-action)
1. [Create an Alexa skill](#5-create-an-alexa-skill)
1. [Talk to it](#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:
```bash
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](https://cloud.ibm.com/registration/) 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](https://developer.ibm.com/code/exchanges/bots),
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`:
* [**Watson Assistant**](https://cloud.ibm.com/catalog/services/watson-assistant)
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`](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](#5-configure-credentials).
![view_api_details](doc/source/images/view_api_details.png)
### 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`](params.sample) to `.params`.
```bash
cp params.sample .params
```
Edit the `.params` file and add the required settings as described below.
#### `params.sample:`
```json
{
"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](#2-create-a-watson-assistant-skill).
### 4. Create the OpenWhisk action
As a prerequisite, [install the Cloud Functions (IBM Cloud OpenWhisk) CLI](https://cloud.ibm.com/docs/openwhisk?topic=cloud-functions-cli_install)
#### 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.
```sh
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](https://cloud.ibm.com/openwhisk/actions), click on your
`alexa-watson` action and use the sidebar to navigate to `Endpoints`.
![functions_endpoints](doc/source/images/functions_endpoints.png)
### 5. Create an Alexa skill
Sign up for an Amazon Developer Portal account [here](https://developer.amazon.com/).
Go to https://developer.amazon.com/alexa/console/ask and click the `Create Skill` button.
![create_alexa_skill](doc/source/images/create_alexa_skill.png)
Provide a name, choose **Custom** model and hit the `Create skill` button.
![select_custom_skill](doc/source/images/select_custom_skill.png)
Select the **Start from scratch** template and hit the `Choose` button.
![select_template](doc/source/images/select_startfromscratch_template.png)
Provide an invocation name:
![invocation_name_v1](doc/source/images/invocation_name_v1.png)
Add a custom slot type:
* In the left sidebar menu, click on `Slot Types (#)` and hit `+ Add`.
![slot_types](doc/source/images/slot_types.png)
* Use the name `BAG_OF_WORDS` and hit the `Create custom slot type` button.
![create_slot_type](doc/source/images/create_slot_type.png)
* 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](doc/source/images/bag_of_words.png)
Add a custom intent type:
* In the left sidebar menu, click on `Intents (#)` and hit `+ Add`.
![intents](doc/source/images/intents.png)
* 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](doc/source/images/sample_utterance.png)
* Scroll down to `Intent Slots (#)`
* Use the `Select a slot type` pulldown to give `EveryThingSlot` the slot type `BAG_OF_WORDS`.
![create_everything_intent](doc/source/images/create_everything_intent.png)
Click on `Save Model` and then `Build Model
没有合适的资源?快使用搜索试试~ 我知道了~
使用IBMWatsonAssistant和IBMCloudFunctions的AlexaSkill_JavaSc.zip
共44个文件
png:24个
json:5个
txt:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 129 浏览量
2023-04-05
13:00:12
上传
评论
收藏 2.8MB ZIP 举报
温馨提示
使用IBMWatsonAssistant和IBMCloudFunctions的AlexaSkill_JavaSc.zip
资源推荐
资源详情
资源评论
收起资源包目录
使用IBMWatsonAssistant和IBMCloudFunctions的AlexaSkill_JavaSc.zip (44个子文件)
alexa-skill-watson-assistant-master
screenshots
dialog-2.png 239KB
alexa-simulator.png 290KB
alexa-config-2.png 306KB
alexa-config-1.png 244KB
alexa-config-3.png 262KB
alexa-config-4.png 220KB
dialog-1.png 228KB
.eslintrc.js 615B
params.sample 135B
.travis.yml 115B
doc
source
images
sample_utterance.png 94KB
select_startfromscratch_template.png 38KB
create_everything_intent.png 143KB
sample_conversation.png 46KB
invocation_name_v1.png 146KB
architecture.png 39KB
slot_types.png 8KB
service_endpoint_type.png 207KB
view_api_details.png 84KB
create_slot_type.png 25KB
functions_endpoints.png 146KB
invocation_name.png 116KB
save_and_build.png 93KB
create_alexa_skill.png 14KB
intents.png 8KB
select_custom_skill.png 170KB
bag_of_words.png 12KB
data
alexa
custom_slot_types.txt 39B
intent_schema.json 184B
sample_utterances.txt 33B
assistant
rent_a_car.json 48KB
LICENSE 11KB
speechAssets
IntentSchema.json 184B
CustomSlotType.txt 39B
SampleUtterances_en_US.txt 33B
main.js 4KB
CONTRIBUTING.md 770B
package.json 823B
package-lock.json 135KB
test
unit
test.main.js 3KB
.gitignore 800B
README.md 10KB
MAINTAINERS.md 3KB
NOTICE 701B
共 44 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功