Skip to content

Commit 6ead645

Browse files
authored
Merge pull request #138 from watson-developer-cloud/assistant
feat: Add semantic releases and IAM support
2 parents 027a795 + 025314a commit 6ead645

25 files changed

+4404
-5808
lines changed

.eslintrc.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
env:
2+
node: true
3+
mocha: true
4+
extends: 'eslint:recommended'
5+
rules:
6+
indent:
7+
- error
8+
- 2
9+
linebreak-style:
10+
- error
11+
- unix
12+
quotes:
13+
- error
14+
- single
15+
semi:
16+
- error
17+
- always
18+
no-console:
19+
- off

.travis.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
language: node_js
2-
sudo: false
3-
node_js: 6
2+
sudo: true
3+
node_js: 8
44
cache:
55
directories:
66
- node_modules
77
script:
8+
- npm run lint
89
- npm test
9-
notifications:
10-
email: false
10+
deploy:
11+
- provider: script
12+
skip_cleanup: true
13+
script:
14+
- bx-blue-green-travis
15+
on:
16+
branch: master
17+
repo: watson-developer-cloud/botkit-middleware
18+
- provider: script
19+
skip_cleanup: true
20+
script: npx semantic-release
21+
on:
22+
node: 8

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v1.8.0
2+
3+
* Added semantic-releases
4+
* Update node-sdk to 3.7.0
5+
* Update to use the Watson Assistant class
6+
17
## v1.6.1
28

39
* Fixed function signatures in Typescript definition file

README.md

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Use IBM Watson's Conversation service to chat with your Botkit-powered Bot! [![Build Status](https://travis-ci.org/watson-developer-cloud/botkit-middleware.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/botkit-middleware)
1+
# Use IBM Watson's Assistant service to chat with your Botkit-powered Bot! [![Build Status](https://travis-ci.org/watson-developer-cloud/botkit-middleware.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/botkit-middleware)
22

3-
This middleware plugin for [Botkit](http://howdy.ai/botkit) allows developers to easily integrate a [Watson Conversation](https://www.ibm.com/watson/developercloud/conversation.html) workspace with multiple social channels like Slack, Facebook, and Twilio. Customers can have simultaneous, independent conversations with a single workspace through different channels.
3+
This middleware plugin for [Botkit](http://howdy.ai/botkit) allows developers to easily integrate a [Watson Assistant](https://www.ibm.com/watson/services/conversation/) workspace with multiple social channels like Slack, Facebook, and Twilio. Customers can have simultaneous, independent conversations with a single workspace through different channels.
44

55
## Middleware Overview
66

@@ -18,7 +18,7 @@ This middleware plugin for [Botkit](http://howdy.ai/botkit) allows developers to
1818
* `hear`: used for [intent matching](#intent-matching).
1919
* `updateContext`: used in [implementing app actions](#implementing-app-actions) (sendToWatson does it better now).
2020
* `readContext`: used in [implementing event handlers](#implementing-event-handlers).
21-
* `before`: [pre-process](#before-and-after) requests before sending to Watson Conversation (Conversation).
21+
* `before`: [pre-process](#before-and-after) requests before sending to Watson Assistant (Conversation).
2222
* `after`: [post-process](#before-and-after) responses before forwarding them to Botkit.
2323

2424

@@ -28,18 +28,26 @@ This middleware plugin for [Botkit](http://howdy.ai/botkit) allows developers to
2828
$ npm install botkit-middleware-watson --save
2929
```
3030

31-
## Usage
31+
## Prerequisites
3232

33-
### Acquire Watson Conversation credentials
33+
1. Sign up for an [IBM Cloud account](https://console.bluemix.net/registration/).
34+
1. Download the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview).
35+
1. Create an instance of the Watson Assistant service and get your credentials:
36+
- Go to the [Watson Assistant](https://console.bluemix.net/catalog/services/conversation) page in the IBM Cloud Catalog.
37+
- Log in to your IBM Cloud account.
38+
- Click **Create**.
39+
- Click **Show** to view the service credentials.
40+
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
41+
- Copy the `url` value.
3442

35-
The middleware needs you to provide the `username`, `password`, and `workspace_id` of your Watson Conversation chat bot. If you have an existing Conversation service instance, follow [these steps](https://github.com/watson-developer-cloud/conversation-simple/blob/master/README.md#configuring-the-application-environmnet) to get your credentials.
43+
1. Create a workspace using the Watson Assistant service and copy the `workspace_id`.
3644

37-
If you do not have a Conversation service instance, follow [these steps](https://github.com/watson-developer-cloud/conversation-simple/blob/master/README.md#before-you-begin) to get started.
3845

3946
### Acquire channel credentials
40-
This document shows code snippets for using a Slack bot with the middleware. (If you want examples for the other channels, see the [examples/multi-bot](/examples/multi-bot) folder. The multi-bot example app shows how to connect to Slack, Facebook, and Twilio IPM bots running on a single Express server.)
47+
This document shows code snippets for using a Slack bot with the middleware. (If you want examples for the other channels, see the [examples/multi-bot](/examples/multi-bot) folder.
48+
The multi-bot example app shows how to connect to Slack, Facebook, and Twilio IPM bots running on a single Express server.)
4149

42-
You need a _Slack token_ for your Slack bot to talk to Conversation.
50+
You need a _Slack token_ for your Slack bot to talk to Watson Assistant.
4351

4452
If you have an existing Slack bot, then copy the Slack token from your Slack settings page.
4553

@@ -61,13 +69,29 @@ var slackBot = slackController.spawn({
6169
});
6270
```
6371

64-
Create the middleware object which you'll use to connect to the Conversation service:
72+
Create the middleware object which you'll use to connect to the Watson Assistant service.
73+
74+
If your credentials are `username` and `password` use:
75+
76+
```js
77+
var watsonMiddleware = require('botkit-middleware-watson')({
78+
username: YOUR_ASSISTANT_USERNAME,
79+
password: YOUR_ASSISTANT_PASSWORD,
80+
url: YOUR_ASSISTANT_URL,
81+
workspace_id: YOUR_WORKSPACE_ID,
82+
version: '2018-07-10',
83+
minimum_confidence: 0.50, // (Optional) Default is 0.75
84+
});
85+
```
86+
87+
If your credentials is `apikey` use:
88+
6589
```js
6690
var watsonMiddleware = require('botkit-middleware-watson')({
67-
username: YOUR_CONVERSATION_USERNAME,
68-
password: YOUR_CONVERSATION_PASSWORD,
91+
iam_apikey: YOUR_API_KEY,
92+
url: YOUR_ASSISTANT_URL,
6993
workspace_id: YOUR_WORKSPACE_ID,
70-
version_date: '2017-05-26',
94+
version: '2018-07-10',
7195
minimum_confidence: 0.50, // (Optional) Default is 0.75
7296
});
7397
```
@@ -98,7 +122,7 @@ Then you're all set!
98122
### Message filtering
99123

100124
When middleware is registered, the receive function is triggered on _every_ message.
101-
If you would like to make your bot to only respond to _direct messages_ using Conversation, you can achieve this in 2 ways:
125+
If you would like to make your bot to only respond to _direct messages_ using Assistant, you can achieve this in 2 ways:
102126

103127
#### Using interpret function instead of registering middleware
104128

@@ -161,7 +185,7 @@ Note: if you want your own `hear()` function to implement pattern matching like
161185

162186
### Implementing app actions
163187

164-
Conversation side of app action is documented in [Developer Cloud](https://www.ibm.com/watson/developercloud/doc/conversation/develop-app.html#implementing-app-actions)
188+
Watson Assistant side of app action is documented in [Developer Cloud](https://console.bluemix.net/docs/services/conversation/develop-app.html#building-a-client-application)
165189
A common scenario of processing actions is
166190
* Send message to user "Please wait while I ..."
167191
* Perform action
@@ -374,21 +398,21 @@ slackController.hears(['hello'], ['direct_message', 'direct_mention', 'mention']
374398

375399
#### `before` and `after`
376400

377-
The _before_ and _after_ callbacks can be used to perform some tasks _before_ and _after_ Conversation is called. One may use it to modify the request/response payloads, execute business logic like accessing a database or making calls to external services.
401+
The _before_ and _after_ callbacks can be used to perform some tasks _before_ and _after_ Assistant is called. One may use it to modify the request/response payloads, execute business logic like accessing a database or making calls to external services.
378402

379403
They can be customized as follows:
380404

381405
```js
382-
middleware.before = function(message, conversationPayload, callback) {
383-
// Code here gets executed before making the call to Conversation.
406+
middleware.before = function(message, assistantPayload, callback) {
407+
// Code here gets executed before making the call to Assistant.
384408
callback(null, customizedPayload);
385409
}
386410
```
387411

388412
```js
389-
middleware.after = function(message, conversationResponse, callback) {
390-
// Code here gets executed after the call to Conversation.
391-
callback(null, conversationResponse);
413+
middleware.after = function(message, assistantResponse, callback) {
414+
// Code here gets executed after the call to Assistant.
415+
callback(null, assistantResponse);
392416
}
393417
```
394418

examples/multi-bot/.env

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#WATSON
2-
# Set CONVERSATION_URL to correct gateway
2+
# Set ASSISTANT_URL to correct gateway
33
# US-South
4-
CONVERSATION_URL=https://gateway.watsonplatform.net/conversation/api
4+
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api
55
# Germany
6-
#CONVERSATION_URL=https://gateway-fra.watsonplatform.net/conversation/api
7-
CONVERSATION_USERNAME=username
8-
CONVERSATION_PASSWORD=password
6+
#ASSISTANT_URL=https://gateway-fra.watsonplatform.net/assistant/api
7+
ASSISTANT_USERNAME=username
8+
ASSISTANT_PASSWORD=password
99
WORKSPACE_ID=your_workspace_id
1010

11+
# if is apikey
12+
#ASSISTANT_IAM_APIKEY=apikey
13+
1114
#SLACK
1215
SLACK_TOKEN=your_slack_bot_token
1316

examples/multi-bot/README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,45 @@ This document describes how to set up a sample Express app which talks to Slack,
1010

1111
## Getting credentials
1212

13-
### Watson Conversation
14-
Follow the steps outlined in [this document](https://github.com/watson-developer-cloud/conversation-simple/blob/master/README.md#configuring-the-app-environment) and paste your Conversation bot's credentials in the sample `.env` file in the project directory.
13+
### Watson Assistant
14+
15+
1. Sign up for an [IBM Cloud account](https://console.bluemix.net/registration/).
16+
1. Download the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview).
17+
1. Create an instance of the Watson Assistant service and get your credentials:
18+
- Go to the [Watson Assistant](https://console.bluemix.net/catalog/services/conversation) page in the IBM Cloud Catalog.
19+
- Log in to your IBM Cloud account.
20+
- Click **Create**.
21+
- Click **Show** to view the service credentials.
22+
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
23+
- Copy the `url` value.
24+
25+
1. Create a workspace using the Watson Assistant service and copy the `workspace_id`.
26+
27+
1. Open the *.env* file and add the service credentials that you obtained in the previous step.
28+
29+
Example *.env* file that configures the `apikey` and `url` for a Watson Assistant service instance hosted in the US East region:
30+
31+
```
32+
ASSISTANT_IAM_APIKEY=X4rbi8vwZmKpXfowaS3GAsA7vdy17Qh7km5D6EzKLHL2
33+
ASSISTANT_URL=https://gateway-wdc.watsonplatform.net/assistant/api
34+
```
35+
36+
- If your service instance uses `username` and `password` credentials, add the `ASSISTANT_USERNAME` and `ASSISTANT_PASSWORD` variables to the *.env* file.
37+
38+
Example *.env* file that configures the `username`, `password`, and `url` for a Watson Assistant service instance hosted in the US South region:
39+
40+
```
41+
ASSISTANT_USERNAME=522be-7b41-ab44-dec3-g1eab2ha73c6
42+
ASSISTANT_PASSWORD=A4Z5BdGENrwu8
43+
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api
44+
```
45+
46+
1. Add the `WORKSPACE_ID` to the previous properties
47+
48+
```
49+
WORKSPACE_ID=522be-7b41-ab44-dec3-g1eab2ha73c6
50+
```
1551
16-
If you don't have a Conversation service instance, follow [these steps](https://github.com/watson-developer-cloud/conversation-simple/blob/master/README.md#before-you-begin) to get started.
1752
1853
### Slack
1954
Follow the Getting Started section of this [document](https://github.com/howdyai/botkit/blob/master/docs/readme-slack.md) from Botkit.
@@ -43,7 +78,7 @@ FB_VERIFY_TOKEN=<your verify token>
4378
FB_APP_SECRET=<your apps secret key>
4479
```
4580
46-
When you're ready to test your bot, go to your Facebook homepage and find the page you created. Click on _Message_ to start chatting with your Watson Conversation bot!
81+
When you're ready to test your bot, go to your Facebook homepage and find the page you created. Click on _Message_ to start chatting with your Watson Assistant bot!
4782
4883
### Twilio IPM
4984
Follow the Getting Started section of this [document](https://github.com/howdyai/botkit/blob/master/docs/readme-twilioipm.md) from Botkit.

examples/multi-bot/app.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
require('dotenv').load();
1818

1919
var middleware = require('botkit-middleware-watson')({
20-
username: process.env.CONVERSATION_USERNAME,
21-
password: process.env.CONVERSATION_PASSWORD,
20+
username: process.env.ASSISTANT_USERNAME,
21+
password: process.env.ASSISTANT_PASSWORD,
2222
workspace_id: process.env.WORKSPACE_ID,
23-
url: process.env.CONVERSATION_URL || 'https://gateway.watsonplatform.net/conversation/api',
24-
version_date: '2017-05-26'
23+
url: process.env.ASSISTANT_URL || 'https://gateway.watsonplatform.net/assistant/api',
24+
version: '2018-07-10'
2525
});
2626

2727
module.exports = function(app) {
@@ -44,11 +44,11 @@ module.exports = function(app) {
4444
console.log('Twilio bot is live');
4545
}
4646
// Customize your Watson Middleware object's before and after callbacks.
47-
middleware.before = function(message, conversationPayload, callback) {
48-
callback(null, conversationPayload);
49-
}
47+
middleware.before = function(message, assistantPayload, callback) {
48+
callback(null, assistantPayload);
49+
};
5050

51-
middleware.after = function(message, conversationResponse, callback) {
52-
callback(null, conversationResponse);
53-
}
51+
middleware.after = function(message, assistantResponse, callback) {
52+
callback(null, assistantResponse);
53+
};
5454
};

examples/multi-bot/bot-facebook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ controller.hears('(.*)', 'message_received', function(bot, message) {
3030
bot.reply(message, message.watsonData.output.text.join('\n'));
3131
} else {
3232
console.log('Error: received message in unknown format. (Is your connection with Watson Conversation up and running?)');
33-
bot.reply(message, "I'm sorry, but for technical reasons I can't respond to your message");
33+
bot.reply(message, 'I\'m sorry, but for technical reasons I can\'t respond to your message');
3434
}
3535
});
3636

examples/multi-bot/bot-slack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ controller.hears(['.*'], ['direct_message', 'direct_mention', 'mention'], functi
2929
bot.reply(message, message.watsonData.output.text.join('\n'));
3030
} else {
3131
console.log('Error: received message in unknown format. (Is your connection with Watson Conversation up and running?)');
32-
bot.reply(message, "I'm sorry, but for technical reasons I can't respond to your message");
32+
bot.reply(message, 'I\'m sorry, but for technical reasons I can\'t respond to your message');
3333
}
3434
});
3535

examples/multi-bot/bot-twilio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ controller.hears(['.*'], 'message_received', function(bot, message) {
3434
bot.reply(message, message.watsonData.output.text.join('\n'));
3535
} else {
3636
console.log('Error: received message in unknown format. (Is your connection with Watson Conversation up and running?)');
37-
bot.reply(message, "I'm sorry, but for technical reasons I can't respond to your message");
37+
bot.reply(message, 'I\'m sorry, but for technical reasons I can\'t respond to your message');
3838
}
3939
});
4040

0 commit comments

Comments
 (0)