Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
.DS_Store
package-lock.json
yarn.lock
63 changes: 62 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,72 @@
## v6.6.0 - Multi-responses in Composer

- Multi-responses in Composer: `runComposerAudio()`, `.runComposer()` (and raw `.converse()` + `.event()`) now emit `response` events for intermediate responses, and run intermediate actions as well.
- Bumped API version to `20230215`.

## v6.5.1
- Update uuid to version 9.0.0

## v6.5.0 - Composer alpha integration

- Composer integration: `.runComposerAudio()`, `.runComposer()` (and raw `.converse()` + `.event()`) + `actions` support
- Bumped API version to `20220801`.
- interactive now uses Composer for text inputs, use `!message` for `GET /message` and `!converse` for Composer audio inputs
- added pizza example

## v6.4.0

- Add `POST /synthesize` integration.
- Add `POST /dictation` integration.
- New example using `synthesize()` and `dictation()`.

## v6.3.0

- `speech()` emits `partialUnderstanding` events to support live understanding.
- `apiVersion` updated to `20220608` and its type is now a number.

## Breaking changes

- Bumped API version to `20220608`.
- Emits `partialUnderstanding` events (live understanding support).
- Updated `apiVersion` type from string to number.

## v6.2.2

- Fixes parsing for large HTTP chunks.

## v6.2.1

- Emits `partialTranscription` and `fullTranscription` events.
- Shows microphone input feedback for `interactive`.
- Includes `proxy` support for `speech()`.

## v6.2.0

Requires Node.js >= 6.17.1 to support ES6 directly.

## v6.1.1

- Basic `POST /speech` integration.
- `!speech` support for interactive.

## v6.1.0

Bumped API version to `20210928`.
Moved API version from `Accept` header to `v` HTTP parameter.
Kaizens.

## v6.0.1

Removed unused `request` dependency
Updated various dependencies.

## v6.0.0

Updated API version to latest: `20200513`.
Browse the latest HTTP API documentation [here](https://wit.ai/docs/http/20200513#get__message_link).

## v5.0.0

The most important change is the removal of `.converse()` and `.runActions()`. Follow the migration tutorial [here](https://github.com/wit-ai/wit-stories-migration-tutorial), or [read more here](https://wit.ai/blog/2017/07/27/sunsetting-stories).

### Breaking changes
Expand All @@ -16,6 +76,7 @@ The most important change is the removal of `.converse()` and `.runActions()`. F
- updated wit-ai-basic-app-for-tests.zip for testing

## v4.3.0

- `converse` and `runActions` are deprecated
- `interactive` now calls `message`

Expand Down Expand Up @@ -46,7 +107,6 @@ We moved to a Promise-based API, instead of callbacks. This makes the code simpl

See `./examples` to see how to use the new API.


### Breaking changes

- `say` renamed to `send` to reflect that it deals with more than just text
Expand All @@ -61,6 +121,7 @@ See `./examples` to see how to use the new API.
- allows for overriding API version, by setting `WIT_API_VERSION`

## v3.3.1

- adding API versioning (defaults to `20160516`)
- warns instead of throwing when validating actions
- fixing null values when cloning context
Expand Down
211 changes: 183 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ npm install --save node-wit
Run in your terminal:

```bash
# Node.js <= 6.x.x, add the flag --harmony_destructuring
node --harmony_destructuring examples/basic.js <MY_TOKEN>
# Node.js >= v6.x.x
node examples/basic.js <MY_TOKEN>
node examples/basic.js <WIT_TOKEN>
```

See `examples` folder for more examples. Some examples have associated .zip files, do not forget to import those [when creating a new app](https://wit.ai/v2/apps) and grab your access token from the Settings section.
See `examples` folder for more examples. Some examples have associated .zip files, do not forget to import those [when creating a new app](https://wit.ai/apps) and grab your access token from the Settings section.

### Messenger integration example

Expand All @@ -30,78 +27,225 @@ See `examples/messenger.js` for a thoroughly documented tutorial.
### Overview

The Wit module provides a Wit class with the following methods:
* `message` - the Wit [message](https://wit.ai/docs/http/20200513#get__message_link) API

You can also require a library function to test out your bot in the terminal. `require('node-wit').interactive`
- `runComposerAudio` - the [Composer](https://wit.ai/docs/recipes#composer) integration for voice;
- `runComposer` - the [Composer](https://wit.ai/docs/recipes#composer) integration for other inputs;
- `converse` - the Wit [converse](https://wit.ai/docs/http/#post__converse_link) API;
- `event` - the Wit [event](https://wit.ai/docs/http#post__event_link) API;
- `message` - the Wit [message](https://wit.ai/docs/http#get__message_link) API;
- `speech` - the Wit [speech](https://wit.ai/docs/http#post__speech_link) API;
- `dictation` - the Wit [dictation](https://wit.ai/docs/http#post__dictation_link) API;
- `synthesize` - the Wit [synthesize](https://wit.ai/docs/http#post__synthesize_link) API.

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

### Wit class

The Wit constructor takes the following parameters:
* `accessToken` - the access token of your Wit instance
* `logger` - (optional) the object handling the logging.
* `apiVersion` - (optional) the API version to use instead of the recommended one

- `accessToken` - the access token of your Wit instance;
- `actions` - the object of [client action definitions for Composer](https://wit.ai/docs/recipes#run-custom-code);
- `logger` - (optional) the object handling the logging;
- `apiVersion` - (optional) the API version to use instead of the recommended one

The `logger` object should implement the methods `debug`, `info`, `warn` and `error`.
They can receive an arbitrary number of parameters to log.
For convenience, we provide a `Logger` class, taking a log level parameter

Example:

```js
const {Wit, log} = require('node-wit');

const actions = {
confirm_order(contextMap) {
return {context_map: {...contextMap, order_confirmation: 'PIZZA42'}};
},
};

const client = new Wit({
accessToken: MY_TOKEN,
logger: new log.Logger(log.DEBUG) // optional
actions,
logger: new log.Logger(log.DEBUG), // optional
});

console.log(client.message('set an alarm tomorrow at 7am'));
```

## .runComposerAudio()

The [Composer](https://wit.ai/docs/recipes#composer) integration for voice.

Takes the following parameters:

- `sessionId` - a unique string identifying the user session
- `contentType` - the Content-Type header
- `body` - the audio `Readable` stream
- `contextMap` - the [context map](https://wit.ai/docs/recipes#custom-context) object

Emits `partialTranscription`, `response` and `fullTranscription` events.
Run the provided `actions` as instructed by the API response, and calls back with the resulting updated context map (unless the action returns `stop: true`).
The Promise returns the final JSON payload of the last API call ([POST /converse](https://wit.ai/docs/http#post__converse_link) or [POST
/event](https://wit.ai/docs/http#post__event_link)).

See `lib/interactive.js` for an example.

## .runComposer()

The [Composer](https://wit.ai/docs/recipes#composer) integration for other
inputs, including text.

Takes the following parameters:

- `sessionId` - a unique string identifying the user session
- `contextMap` - the [context map](https://wit.ai/docs/recipes#custom-context) object
- `message` - the optional user text query

Emits `response` events.
Run the provided `actions` as instructed by the API response, and calls back with the resulting updated context map (unless the action returns `stop: true`).
The Promise returns the final JSON payload of the last [POST /event](https://wit.ai/docs/http#post__event_link) API call.

See `lib/interactive.js` for an example.

## .converse()

The Wit [converse](https://wit.ai/docs/http/#post__converse_link) API.

Takes the following parameters:

- `sessionId` - a unique string identifying the user session
- `contentType` - the Content-Type header
- `body` - the audio `Readable` stream
- `contextMap` - the [context map](https://wit.ai/docs/recipes#custom-context) object

Emits `partialTranscription`, `fullTranscription`, and `response` events. Runs
intermediate `actions` as instructed by the API.

We recommend to use `.runComposerAudio()` instead of this raw API.

## .event()

The Wit [event](https://wit.ai/docs/http#post__event_link) API.

Takes the following parameters:

- `sessionId` - a unique string identifying the user session
- `contextMap` - the [context map](https://wit.ai/docs/recipes#custom-context) object
- `message` - the optional user text query

Emits `response` events, and run intermediate `actions` as instructed by the API.

We recommend to use `.runComposer()` instead of this raw API.

### .message()

The Wit [message](https://wit.ai/docs/http/20200513#get__message_link) API.
The Wit [message](https://wit.ai/docs/http/#get__message_link) API.

Takes the following parameters:
* `message` - the text you want Wit.ai to extract the information from
* `context` - (optional) the object representing the session state

- `q` - the text input you want Wit.ai to extract the information from
- `context` - (optional) the [Context](https://wit.ai/docs/http/#context_link) object
- `n` - (optional) the max number of intents and traits to get back

Example:

```js
const client = new Wit({accessToken: 'MY_TOKEN'});
client.message('what is the weather in London?', {})
.then((data) => {
console.log('Yay, got Wit.ai response: ' + JSON.stringify(data));
})
.catch(console.error);
client
.message('what is the weather in London?', {})
.then(data => {
console.log('Yay, got Wit.ai response: ' + JSON.stringify(data));
})
.catch(console.error);
```

See `lib/interactive.js` for another example integration.

### .speech()

The Wit [speech](https://wit.ai/docs/http#post__speech_link) API.

Takes the following paramters:

- `contentType` - the Content-Type header
- `body` - the audio `Readable` stream
- `context` - (optional) the [Context](https://wit.ai/docs/http/#context_link) object
- `n` - (optional) the max number of intents and traits to get back

Emits `partialTranscription`, `partialUnderstanding` and `fullTranscription` events.
The Promise returns the final JSON payload.

See `lib/interactive.js` for an example.

### .dictation()

The Wit [dictation](https://wit.ai/docs/http#post__dictation_link) API.

Takes the following paramters:

- `contentType` - the Content-Type header
- `body` - the audio `Readable` stream

Emits `partialTranscription`, and `fullTranscription` events.
The Promise returns the final JSON payload.

See `examples/synthesize-speech.js` for an example.

### .synthesize()

The Wit [synthesize](https://wit.ai/docs/http#post__synthesize_link) API.

Takes the following paramters (click on link above for more details):

- `q` - The query containting text to synthesize
- `voice` - The voice name. For voices and styles available, see GET [voices.](https://wit.ai/docs/http#get__voices_link)
- `style` - (optional) The style to speak in
- `speed` - (optional) the speed the text is spoken
- `pitch` - (optional) the pitch of the audio
- `gain` - (optional) the gain of the audio

The Promise returns the final response, with the body containing the audio stream of the synthesized text.

See `examples/synthesize-speech.js` for an example.

### interactive

Starts an interactive conversation with your bot.
Starts an interactive conversation with your Wit app.

Full conversational interactions:
Use `!converse` to send an audio request from the microphone using Composer.
Enter any text input to send a text request using Composer.

One-off natural language requests:
Use `!speech` to send an audio request from the microphone.
Use `!message <your message>` to send a text request.

Example:

```js
const {interactive} = require('node-wit');
interactive(client);
```

See the [docs](https://wit.ai/docs) for more information.


## Changing the API version

The default (recommended, latest) API version is set in `config.js`.

On May 13th, 2020, the `GET /message` API was updated to reflect the new data model: intents, traits and entities are now distinct.
We updated the SDK to the latest version: `20200513`.
You can target a specific version by passing the `apiVersion` parameter when creating the `Wit` object.

```json
{
"text": "hello",
"intents": [ {
"id": "1353535345345",
"name": "greet",
"confidence": 0.9753
} ],
"intents": [
{
"id": "1353535345345",
"name": "greet",
"confidence": 0.9753
}
],
"entities": [],
"traits": []
}
Expand All @@ -115,4 +259,15 @@ You can target a specific version by passing the `apiVersion` parameter when cre

## License

The license for node-wit can be found in LICENSE file in the root directory of this source tree.
The license for node-wit can be found in LICENSE file in the root directory of
this source tree.

## Terms of Use
Our terms of use can be found at https://opensource.facebook.com/legal/terms.

Use of Wit.ai services fall under the terms of use found here: https://wit.ai/terms.

## Privacy Policy
Our privacy policy can be found at https://opensource.facebook.com/legal/privacy.

The privacy policy for the Wit.ai service can be found at https://wit.ai/privacy.
2 changes: 1 addition & 1 deletion examples/basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
* Copyright (c) Meta Platforms, Inc. and its affiliates. All Rights Reserved.
*/

'use strict';
Expand Down
Loading