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: README.md
+81-68Lines changed: 81 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,31 @@
2
2
3
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.
* Automatically manages context in multi-turn conversations to keep track of where the user left off in the conversation.
@@ -25,20 +50,20 @@ This middleware plugin for [Botkit](http://howdy.ai/botkit) allows developers to
25
50
## Installation
26
51
27
52
```sh
28
-
$ npm install botkit-middleware-watson --save
53
+
$ npm install botkit-middleware-watson
29
54
```
30
55
31
56
## Prerequisites
32
57
33
-
1. Sign up for an [IBM Cloud account](https://console.bluemix.net/registration/).
58
+
1. Sign up for an [IBM Cloud account](https://cloud.ibm.com/registration/).
34
59
1. Create an instance of the Watson Assistant service and get your credentials:
35
-
- Go to the [Watson Assistant](https://console.bluemix.net/catalog/services/conversation) page in the IBM Cloud Catalog.
60
+
- Go to the [Watson Assistant](https://cloud.ibm.com/catalog/services/conversation) page in the IBM Cloud Catalog.
36
61
- Log in to your IBM Cloud account.
37
62
- Click **Create**.
38
63
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
39
64
- Copy the `url` value.
40
65
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).
66
+
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://cloud.ibm.com/docs/services/conversation/getting-started.html).
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:
184
209
```js
185
210
controller.changeEars(watsonMiddleware.hear)
@@ -189,7 +214,7 @@ Note: if you want your own `hear()` function to implement pattern matching like
189
214
190
215
### Implementing app actions
191
216
192
-
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)
217
+
Watson Assistant side of app action is documented in [Developer Cloud](https://cloud.ibm.com/docs/services/assistant/deploy-custom-app.html#deploy-custom-app)
193
218
A common scenario of processing actions is:
194
219
195
220
* Send message to user "Please wait while I ..."
@@ -198,21 +223,19 @@ A common scenario of processing actions is:
198
223
* Send message to Watson with updated context
199
224
* Send result message(s) to user.
200
225
201
-
### using sendToWatson to update context (possible since v1.5.0)
226
+
### Using sendToWatson to update context
202
227
203
228
Using sendToWatson to update context simplifies the bot code compared to solution using updateContext below.
// now do something special related to the hello intent
306
319
});
307
320
```
308
321
309
322
#### `before` and `after`
310
323
311
-
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.
324
+
The _before_ and _after_async calls 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.
// Code here gets executed after the call to Assistant.
338
+
returnassistantResponse;
339
+
});
327
340
```
328
341
329
342
#### Dynamic workspace
330
343
331
-
If you need to make use of multiple workspaces in a single bot, workspace_id can be changed dynamically by setting workspace_id property in context.
344
+
If you need to make use of multiple workspaces in a single bot, `workspace_id` can be changed dynamically by setting `workspace_id` property in context.
332
345
333
-
Example of setting workspace_id to id provided as a property of hello message:
334
-
```typescript
335
-
asyncfunctionhandleHelloEvent(bot, message) {
346
+
Example of setting `workspace_id` to id provided as a property of hello message:
347
+
```js
348
+
asynchandleHelloEvent=(bot, message)=> {
336
349
message.type='welcome';
337
350
constcontextDelta= {};
338
351
@@ -341,7 +354,7 @@ async function handleHelloEvent(bot, message) {
0 commit comments