You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,8 @@
21
21
22
22
## v1.4.2
23
23
24
-
Fixed critical issue introduced in v1.4.1:
25
-
updateContext fails on first write for a new user when simple storage is used
26
-
(It happens because simple storage returns an error when record does not exist).
24
+
* Fixed critical issue introduced in v1.4.1
25
+
* updateContext fails on first write for a new user when simple storage is used (It happens because simple storage returns an error when record does not exist).
Copy file name to clipboardExpand all lines: README.md
+26-28Lines changed: 26 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Use IBM Watson's Assistant service to chat with your Botkit-powered Bot! [](https://travis-ci.org/watson-developer-cloud/botkit-middleware)
2
2
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.
3
+
This middleware plugin for [Botkit](http://howdy.ai/botkit) allows developers to easily integrate a [Watson Assistant](https://www.ibm.com/watson/ai-assistant/) workspace with multiple social channels like Slack, Facebook, and Twilio. Customers can have simultaneous, independent conversations with a single workspace through different channels.
4
4
5
5
## Middleware Overview
6
6
@@ -18,7 +18,7 @@ This middleware plugin for [Botkit](http://howdy.ai/botkit) allows developers to
18
18
*`hear`: used for [intent matching](#intent-matching).
19
19
*`updateContext`: used in [implementing app actions](#implementing-app-actions) (sendToWatson does it better now).
20
20
*`readContext`: used in [implementing event handlers](#implementing-event-handlers).
21
-
*`before`: [pre-process](#before-and-after) requests before sending to Watson Assistant (Conversation).
21
+
*`before`: [pre-process](#before-and-after) requests before sending to Watson Assistant (formerly Conversation).
22
22
*`after`: [post-process](#before-and-after) responses before forwarding them to Botkit.
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
34
1. Create an instance of the Watson Assistant service and get your credentials:
36
35
- Go to the [Watson Assistant](https://console.bluemix.net/catalog/services/conversation) page in the IBM Cloud Catalog.
37
36
- Log in to your IBM Cloud account.
38
37
- Click **Create**.
39
-
- Click **Show** to view the service credentials.
40
38
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
41
39
- Copy the `url` value.
42
40
43
-
1. Create a workspace using the Watson Assistant service and copy the `workspace_id`.
41
+
1. Create a workspace using the Watson Assistant service and copy the `workspace_id`. If you don't know how to create a workspace follow the [Getting Started tutorial](https://console.bluemix.net/docs/services/conversation/getting-started.html).
44
42
45
43
46
44
### Acquire channel credentials
@@ -51,20 +49,20 @@ You need a _Slack token_ for your Slack bot to talk to Watson Assistant.
51
49
52
50
If you have an existing Slack bot, then copy the Slack token from your Slack settings page.
53
51
54
-
Otherwise, follow [Botkit's instructions](https://github.com/howdyai/botkit/blob/master/docs/readme-slack.md) to create your Slack bot from scratch. When your bot is ready, you are provided with a Slack token.
52
+
Otherwise, follow [Botkit's instructions](https://botkit.ai/docs/provisioning/slack-events-api.html) to create your Slack bot from scratch. When your bot is ready, you are provided with a Slack token.
55
53
56
54
### Bot setup
57
55
58
56
This section walks you through code snippets to set up your Slack bot. If you want, you can jump straight to the [full example](/examples/simple-bot).
59
57
60
58
In your app, add the following lines to create your Slack controller using Botkit:
61
59
```js
62
-
var slackController =Botkit.slackbot();
60
+
constslackController=Botkit.slackbot();
63
61
```
64
62
65
63
Spawn a Slack bot using the controller:
66
64
```js
67
-
var slackBot =slackController.spawn({
65
+
constslackBot=slackController.spawn({
68
66
token:YOUR_SLACK_TOKEN
69
67
});
70
68
```
@@ -74,7 +72,7 @@ Create the middleware object which you'll use to connect to the Watson Assistant
74
72
If your credentials are `username` and `password` use:
75
73
76
74
```js
77
-
var watsonMiddleware =require('botkit-middleware-watson')({
You can find the default implementation of this function [here](https://github.com/watson-developer-cloud/botkit-middleware/blob/e29b002f2a004f6df57ddf240a3fdf8cb28f95d0/lib/middleware/index.js#L40). If you want, you can redefine this function in the same way that watsonMiddleware.before and watsonMiddleware.after can be redefined. Refer to the [Botkit Middleware documentation](https://github.com/howdyai/botkit/blob/master/docs/middleware.md#hear-middleware) for an example. Then, to use this function instead of Botkit's default pattern matcher (that does not use minimum_confidence), plug it in using:
177
+
You can find the default implementation of this function [here](https://github.com/watson-developer-cloud/botkit-middleware/blob/e29b002f2a004f6df57ddf240a3fdf8cb28f95d0/lib/middleware/index.js#L40). If you want, you can redefine this function in the same way that watsonMiddleware.before and watsonMiddleware.after can be redefined. Refer to the [Botkit Middleware documentation](https://botkit.ai/docs/core.html#controllerhears) for an example. Then, to use this function instead of Botkit's default pattern matcher (that does not use minimum_confidence), plug it in using:
180
178
```js
181
179
controller.changeEars(watsonMiddleware.hear)
182
180
```
183
181
184
-
Note: if you want your own `hear()` function to implement pattern matching like Botkit's default one, you will likely need to implement that yourself. Botkit's default set of 'ears' is the `hears_regexp` function which is implemented [here](https://github.com/howdyai/botkit/blob/77b7d7f80c46d5c8194453667d22118b7850e252/lib/CoreBot.js#L1180).
182
+
Note: if you want your own `hear()` function to implement pattern matching like Botkit's default one, you will likely need to implement that yourself. Botkit's default set of 'ears' is the `hears_regexp` function which is implemented [here](https://github.com/howdyai/botkit/blob/77b7d7f80c46d5c8194453667d22118b7850e252/lib/CoreBot.js#L1187).
185
183
186
184
### Implementing app actions
187
185
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)
189
-
A common scenario of processing actions is
186
+
Watson Assistant side of app action is documented in [Developer Cloud](https://console.bluemix.net/docs/services/assistant/deploy-custom-app.html#deploy-custom-app)
187
+
A common scenario of processing actions is:
188
+
190
189
* Send message to user "Please wait while I ..."
191
190
* Perform action
192
191
* Persist results in conversation context
@@ -200,17 +199,16 @@ Using sendToWatson to update context simplifies the bot code compared to solutio
200
199
201
200
functioncheckBalance(context, callback) {
202
201
//do something real here
203
-
204
-
var contextDelta = {
202
+
constcontextDelta= {
205
203
validAccount:true,
206
204
accountBalance:95.33
207
205
};
208
206
callback(null, context);
209
207
}
210
208
211
-
var checkBalanceAsync =Promise.promisify(checkBalance);
0 commit comments