Skip to content

Commit 156edad

Browse files
author
Willy Blandin
committed
refocus on NLP + deprecate converse
1 parent 8fea984 commit 156edad

File tree

7 files changed

+1968
-62
lines changed

7 files changed

+1968
-62
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
dist
1+
/dist
22
node_modules
3+
.DS_Store

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v4.3.0
2+
- `converse` and `runActions` are deprecated
3+
- `interactive` now calls `message`
4+
15
## v4.2.0
26

37
- support actions that do not return promises

README.md

+21-50
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,16 @@ See `examples/messenger.js` for a thoroughly documented tutorial.
3131

3232
The Wit module provides a Wit class with the following methods:
3333
* `message` - the Wit [message](https://wit.ai/docs/http/20160330#get-intent-via-text-link) API
34-
* `converse` - the low-level Wit [converse](https://wit.ai/docs/http/20160330#converse-link) API
35-
* `runActions` - a higher-level method to the Wit converse API
3634

3735
You can also require a library function to test out your bot in the terminal. `require('node-wit').interactive`
3836

3937
### Wit class
4038

4139
The Wit constructor takes the following parameters:
4240
* `accessToken` - the access token of your Wit instance
43-
* `actions` - (optional if only using `.message()`) the object with your actions
4441
* `logger` - (optional) the object handling the logging.
4542
* `apiVersion` - (optional) the API version to use instead of the recommended one
4643

47-
The `actions` object has action names as properties, and action functions as values.
48-
Action implementations must return Promises (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
49-
You must provide at least an implementation for the special action `send`.
50-
51-
* `send` takes 2 parameters: `request` and `response`
52-
* custom actions take 1 parameter: `request`
53-
54-
#### Request
55-
* `sessionId` (string) - a unique identifier describing the user session
56-
* `context` (object) - the object representing the session state
57-
* `text` (string) - the text message sent by your end-user
58-
* `entities` (object) - the entities extracted by Wit's NLU
59-
60-
#### Response
61-
* `text` (string) - The text your bot needs to send to the user (as described in your Wit.ai Stories)
62-
* `quickreplies`
63-
6444
The `logger` object should implement the methods `debug`, `info`, `warn` and `error`.
6545
They can receive an arbitrary number of parameters to log.
6646
For convenience, we provide a `Logger` class, taking a log level parameter
@@ -71,25 +51,13 @@ const {Wit, log} = require('node-wit');
7151

7252
const client = new Wit({
7353
accessToken: MY_TOKEN,
74-
actions: {
75-
send(request, response) {
76-
return new Promise(function(resolve, reject) {
77-
console.log(JSON.stringify(response));
78-
return resolve();
79-
});
80-
},
81-
myAction({sessionId, context, text, entities}) {
82-
console.log(`Session ${sessionId} received ${text}`);
83-
console.log(`The current context is ${JSON.stringify(context)}`);
84-
console.log(`Wit extracted ${JSON.stringify(entities)}`);
85-
return Promise.resolve(context);
86-
}
87-
},
8854
logger: new log.Logger(log.DEBUG) // optional
8955
});
56+
57+
console.log(client.message('set an alarm tomorrow at 7am'));
9058
```
9159

92-
### message
60+
### .message()
9361

9462
The Wit [message](https://wit.ai/docs/http/20160330#get-intent-via-text-link) API.
9563

@@ -107,7 +75,21 @@ client.message('what is the weather in London?', {})
10775
.catch(console.error);
10876
```
10977

110-
### runActions
78+
### interactive
79+
80+
Starts an interactive conversation with your bot.
81+
82+
Example:
83+
```js
84+
const {interactive} = require('node-wit');
85+
interactive(client);
86+
```
87+
88+
See the [docs](https://wit.ai/docs) for more information.
89+
90+
### .runActions()
91+
92+
**DEPRECATED** See [our blog post](https://wit.ai/blog/2017/07/27/sunsetting-stories) for a migration plan.
11193

11294
A higher-level method to the Wit converse API.
11395
`runActions` resets the last turn on new messages and errors.
@@ -138,7 +120,9 @@ client.runActions(sessionId, 'what is the weather in London?', context0)
138120

139121
See `./examples/messenger.js` for a full-fledged example
140122

141-
### converse
123+
### .converse()
124+
125+
**DEPRECATED** See [our blog post](https://wit.ai/blog/2017/07/27/sunsetting-stories) for a migration plan.
142126

143127
The low-level Wit [converse](https://wit.ai/docs/http/20160330#converse-link) API.
144128

@@ -157,19 +141,6 @@ client.converse('my-user-session-42', 'what is the weather in London?', {})
157141
.catch(console.error);
158142
```
159143

160-
### interactive
161-
162-
Starts an interactive conversation with your bot.
163-
164-
Example:
165-
```js
166-
const {interactive} = require('node-wit');
167-
interactive(client);
168-
```
169-
170-
See the [docs](https://wit.ai/docs) for more information.
171-
172-
173144
## Changing the API version
174145

175146
On 2016, May 11th, the /message API was updated to reflect the new Bot Engine model: intent are now entities.

lib/interactive.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
const {DEFAULT_MAX_STEPS} = require('./config');
44
const logger = require('./log.js');
55
const readline = require('readline');
6-
const uuid = require('uuid');
76

8-
module.exports = (wit, initContext, maxSteps) => {
9-
let context = typeof initContext === 'object' ? initContext : {};
10-
const sessionId = uuid.v1();
11-
12-
const steps = maxSteps ? maxSteps : DEFAULT_MAX_STEPS;
7+
module.exports = (wit, context) => {
138
const rl = readline.createInterface({
149
input: process.stdin,
1510
output: process.stdout,
@@ -25,9 +20,9 @@ module.exports = (wit, initContext, maxSteps) => {
2520
if (!line) {
2621
return prompt();
2722
}
28-
wit.runActions(sessionId, line, context, steps)
29-
.then((ctx) => {
30-
context = ctx;
23+
wit.message(line, context)
24+
.then((rsp) => {
25+
console.log(JSON.stringify(rsp));
3126
prompt();
3227
})
3328
.catch(err => console.error(err))

lib/wit.js

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ const validate = (opts) => {
208208
};
209209
opts.logger = opts.logger || new log.Logger(log.INFO);
210210
if (opts.actions) {
211+
opts.logger.warn('Stories and POST /converse have been deprecated. This will break in February 2018!');
211212
opts.actions = validateActions(opts.logger, opts.actions);
212213
}
213214

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-wit",
3-
"version": "4.2.0",
3+
"version": "4.3.0",
44
"description": "Wit.ai Node.js SDK",
55
"keywords": [
66
"wit",
@@ -13,7 +13,7 @@
1313
],
1414
"main": "index.js",
1515
"scripts": {
16-
"test": "mocha ./tests/lib.js"
16+
"test": "mocha --timeout 10000 ./tests/lib.js"
1717
},
1818
"repository": "https://github.com/wit-ai/node-wit",
1919
"author": "The Wit Team <[email protected]>",

0 commit comments

Comments
 (0)