Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

node-wit

Node.js SDK for Wit.ai

Subscribe to updates I use node-wit


Statistics on node-wit

Number of watchers on Github 1304
Number of open issues 64
Average time to close an issue 6 days
Main language JavaScript
Average time to merge a PR 3 days
Open pull requests 14+
Closed pull requests 9+
Last commit over 1 year ago
Repo Created over 3 years ago
Repo Last Updated over 1 year ago
Size 114 KB
Organization / Authorwit-ai
Latest Releasev4.1.0
Contributors5
Page Updated
Do you use node-wit? Leave a review!
View open issues (64)
View node-wit activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating node-wit for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Wit Node.js SDK npm

node-wit is the Node.js SDK for Wit.ai.

Install

In your Node.js project, run:

npm install --save node-wit

Quickstart

Run in your terminal:

# 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>

See examples folder for more examples.

Messenger integration example

See examples/messenger.js for a thoroughly documented tutorial.

Overview

The Wit module provides a Wit class with the following methods:

You can also require a library function to test out your bot 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

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:

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

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

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

.message()

The Wit message 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

Example:

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);

interactive

Starts an interactive conversation with your bot.

Example:

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

See the docs for more information.

Changing the API version

On 2016, May 11th, the /message API was updated to reflect the new Bot Engine model: intent are now entities. We updated the SDK to the latest version: 20160516. You can target a specific version by passing the apiVersion parameter when creating the Wit object.

{
  "msg_id" : "e86468e5-b9e8-4645-95ce-b41a66fda88d",
  "_text" : "hello",
  "entities" : {
    "intent" : [ {
      "confidence" : 0.9753469589149633,
      "value" : "greetings"
    } ]
  }
}

Version prior to 20160511 will return the old format:

{
  "msg_id" : "722fc79b-725c-4ca1-8029-b7f57ff88f54",
  "_text" : "hello",
  "outcomes" : [ {
    "_text" : "hello",
    "confidence" : null,
    "intent" : "default_intent",
    "entities" : {
      "intent" : [ {
        "confidence" : 0.9753469589149633,
        "value" : "greetings"
      } ]
    }
  } ],
  "WARNING" : "DEPRECATED"
}

Running tests

  1. Create a new app in wit.ai web console using tests/wit-ai-basic-app-for-tests.zip
  2. Copy the Server Access Token from app settings
  3. Run WIT_TOKEN=XXX npm test, where XXX is the Server Access Token
node-wit open issues Ask a question     (View All Issues)
  • almost 3 years Action when no intent detected
  • almost 3 years session id invalid
  • almost 3 years Confidence Jumps to 2.0416216798903555e-7
  • almost 3 years send first message
  • almost 3 years Syntax Error while running the Examples.
  • almost 3 years is there the error doc ?
  • almost 3 years Structured input
  • almost 3 years new Wit throws -> Error: The second parameter should be an Object.
  • about 3 years Does not work with AWS Lambda: Unexpected token {
  • about 3 years Node v5.5.0: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
  • about 3 years Context is always empty
  • about 3 years Calling last Action instead of others Action
  • about 3 years Remove harmony-destructuring in node-wit
  • about 3 years warnings about argument lengths, when creating higher-order actions
  • about 3 years Issues in when integrating with FB bot.
  • about 3 years FB Messenger integration - Generic Template as reponse from wit.ai
  • about 3 years [wit] Max steps reached, stopping.
  • about 3 years Entity object is empty
  • about 3 years X-Hub-Signature verification fails
  • about 3 years I can't access wit.ai service.
  • about 3 years When I run the quickstart.js, I have got this error.
  • about 3 years Error when Input Message with facebook emoji
  • about 3 years TypeError from wit.js
  • about 3 years QuickStart is broken
  • over 3 years [Question] Is it required to highlight intent value ?
  • over 3 years Error when I try npm install node-wit
  • over 3 years Very odd results when passing a session id starting with '/#'
  • over 3 years Windows (only?) Null Buffer Length
  • over 3 years Invalid session id
  • over 3 years [error] [converse] Error: Bad auth, check token/params
node-wit open pull requests (View All Pulls)
  • enable proxy if https_proxy taken by env
  • Fix #64. Check for bot's message
  • rebase + fix error handling + fix context not optional in message
  • Fixing for #57
  • fix the #55
  • Added missing firstEntity function
  • Fix #51 - required node version
  • Implement handling for quick replies
  • Adds babel for supporting older node versions
  • Feature set max steps in constructor
  • clearer error when stories have an error
  • Added a more updated alternative to isomorphic-fetch.
  • Add confidence field to send method in runActions
  • messenger example: remove unused request module
node-wit list of languages used
node-wit latest release notes
v4.1.0 Node.js SDK - Support for differnt JS envs + converse reset
  • Support for different JS environments
  • converse now takes reset as an optional parameter

Breaking changes

  • interactive is no longer a function on the Wit client. Instead, you require it from the library: require('node-wit').interactive
  • runActions now resets the last turn on new messages and errors.
4.0.0 v4.0.0
  • say renamed to send to reflect that it deals with more than just text
  • Removed built-in actions merge and error
  • Actions signature simplified with request and response arguments
  • Actions need to return promises and do not receive the cb parameter anymore
  • INFO level replaces LOG level
  • configuration is now done when instantiating the Wit object, instead of using env vars
3.3.2 Node.js SDK - custom API versioning
  • allows for targeting a specific API version, by setting WIT_API_VERSION
Other projects in JavaScript