Skip to content

Commit

Permalink
v3.2.0 unifying action parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
patapizza committed Apr 15, 2016
1 parent b9ed1a4 commit f1bc8ef
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 141 deletions.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## v3.2.0

Unifying action parameters.

### breaking

- the `say` action now takes 4 parameters: `sessionId`, `context`, `message`, `cb`
- the `error` action now takes 3 parameters: `sessionId`, `context`, `error`

## v3.1.0

Updating action parameters.

### breaking

- the `merge` action now takes 5 parameters: `sessionId`, `context`, `entities`, `message`, `cb`
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ npm install --save node-wit

## Quickstart

Copy `examples/template.js` to `app.js`:
Run in your terminal:

```bash
cp examples/template.js app.js
```

Then run in your terminal:

```bash
node app.js
node examples/template.js <your_token>
```

See `examples` folder for more examples.
Expand Down Expand Up @@ -49,15 +43,15 @@ You need to provide at least an implementation for the special actions `say`, `m
A minimal `actions` object looks like this:
```js
const actions = {
say: (sessionId, msg, cb) => {
console.log(msg);
say: (sessionId, context, message, cb) => {
console.log(message);
cb();
},
merge: (sessionId, context, entities, message, cb) => {
cb(context);
},
error: (sessionId, context) => {
console.log('Oops, I don\'t know what to do.');
error: (sessionId, context, error) => {
console.log(error.message);
},
};
```
Expand Down
8 changes: 4 additions & 4 deletions examples/joke.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const firstEntityValue = (entities, entity) => {
};

const actions = {
say: (sessionId, msg, cb) => {
console.log(msg);
say: (sessionId, context, message, cb) => {
console.log(message);
cb();
},
merge: (sessionId, context, entities, message, cb) => {
Expand All @@ -60,8 +60,8 @@ const actions = {
}
cb(context);
},
error: (sessionId, context) => {
console.log('Oops, I don\'t know what to do.');
error: (sessionId, context, error) => {
console.log(error.message);
},
'select-joke': (sessionId, context, cb) => {
const jokes = allJokes[context.cat || 'default'];
Expand Down
8 changes: 4 additions & 4 deletions examples/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ const findOrCreateSession = (fbid) => {

// Our bot actions
const actions = {
say: (sessionId, msg, cb) => {
say: (sessionId, context, message, cb) => {
// Our bot has something to say!
// Let's retrieve the Facebook user whose session belongs to
const recipientId = sessions[sessionId].fbid;
if (recipientId) {
// Yay, we found our recipient!
// Let's forward our bot response to her.
fbMessage(recipientId, msg, (err, data) => {
fbMessage(recipientId, message, (err, data) => {
if (err) {
console.log(
'Oops! An error occurred while forwarding the response to',
Expand All @@ -140,8 +140,8 @@ const actions = {
merge: (sessionId, context, entities, message, cb) => {
cb(context);
},
error: (sessionId, context) => {
console.log('Oops, I don\'t know what to do.');
error: (sessionId, context, error) => {
console.log(error.message);
},
// You should implement your custom actions here
// See https://wit.ai/docs/quickstart
Expand Down
8 changes: 4 additions & 4 deletions examples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const firstEntityValue = (entities, entity) => {
};

const actions = {
say: (sessionId, msg, cb) => {
console.log(msg);
say: (sessionId, context, message, cb) => {
console.log(message);
cb();
},
merge: (sessionId, context, entities, message, cb) => {
Expand All @@ -40,8 +40,8 @@ const actions = {
}
cb(context);
},
error: (sessionId, context) => {
console.log('Oops, I don\'t know what to do.');
error: (sessionId, context, error) => {
console.log(error.message);
},
'fetch-weather': (sessionId, context, cb) => {
// Here should go the api call, e.g.:
Expand Down
8 changes: 4 additions & 4 deletions examples/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const token = (() => {
})();

const actions = {
say: (sessionId, msg, cb) => {
console.log(msg);
say: (sessionId, context, message, cb) => {
console.log(message);
cb();
},
merge: (sessionId, context, entities, message, cb) => {
cb(context);
},
error: (sessionId, context) => {
console.log('Oops, I don\'t know what to do.');
error: (sessionId, context, err) => {
console.log(err.message);
},
};

Expand Down
Loading

0 comments on commit f1bc8ef

Please sign in to comment.