@@ -31,36 +31,16 @@ See `examples/messenger.js` for a thoroughly documented tutorial.
31
31
32
32
The Wit module provides a Wit class with the following methods:
33
33
* ` 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
36
34
37
35
You can also require a library function to test out your bot in the terminal. ` require('node-wit').interactive `
38
36
39
37
### Wit class
40
38
41
39
The Wit constructor takes the following parameters:
42
40
* ` accessToken ` - the access token of your Wit instance
43
- * ` actions ` - (optional if only using ` .message() ` ) the object with your actions
44
41
* ` logger ` - (optional) the object handling the logging.
45
42
* ` apiVersion ` - (optional) the API version to use instead of the recommended one
46
43
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
-
64
44
The ` logger ` object should implement the methods ` debug ` , ` info ` , ` warn ` and ` error ` .
65
45
They can receive an arbitrary number of parameters to log.
66
46
For convenience, we provide a ` Logger ` class, taking a log level parameter
@@ -71,25 +51,13 @@ const {Wit, log} = require('node-wit');
71
51
72
52
const client = new Wit ({
73
53
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
- },
88
54
logger: new log.Logger (log .DEBUG ) // optional
89
55
});
56
+
57
+ console .log (client .message (' set an alarm tomorrow at 7am' ));
90
58
```
91
59
92
- ### message
60
+ ### . message()
93
61
94
62
The Wit [ message] ( https://wit.ai/docs/http/20160330#get-intent-via-text-link ) API.
95
63
@@ -107,7 +75,21 @@ client.message('what is the weather in London?', {})
107
75
.catch (console .error );
108
76
```
109
77
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.
111
93
112
94
A higher-level method to the Wit converse API.
113
95
` runActions ` resets the last turn on new messages and errors.
@@ -138,7 +120,9 @@ client.runActions(sessionId, 'what is the weather in London?', context0)
138
120
139
121
See ` ./examples/messenger.js ` for a full-fledged example
140
122
141
- ### converse
123
+ ### .converse()
124
+
125
+ ** DEPRECATED** See [ our blog post] ( https://wit.ai/blog/2017/07/27/sunsetting-stories ) for a migration plan.
142
126
143
127
The low-level Wit [ converse] ( https://wit.ai/docs/http/20160330#converse-link ) API.
144
128
@@ -157,19 +141,6 @@ client.converse('my-user-session-42', 'what is the weather in London?', {})
157
141
.catch (console .error );
158
142
```
159
143
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
-
173
144
## Changing the API version
174
145
175
146
On 2016, May 11th, the /message API was updated to reflect the new Bot Engine model: intent are now entities.
0 commit comments