Giter Site home page Giter Site logo

node-wit's Introduction

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. Some examples have associated .zip files, do not forget to import those when creating a new app and grab your access token from the Settings section.

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

{
  "text": "hello",
  "intents": [ {
    "id": "1353535345345",
    "name": "greet",
    "confidence": 0.9753
  } ],
  "entities": [],
  "traits": []
}

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

License

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

node-wit's People

Contributors

patapizza avatar dependabot[bot] avatar stopachka avatar jtliao avatar jedireza avatar chessai avatar diegorbaquero avatar glavin001 avatar nuoomnoy02 avatar blandinw avatar amowu avatar chrispanag avatar laardee avatar fengyangzhang avatar gleuch avatar kartikchugh avatar oniken avatar keyvanakbary avatar marcbachmann avatar ptab avatar vbhaip avatar duffmeister avatar kidexp avatar rdbmax avatar tunilame avatar ush189 avatar

Stargazers

 avatar

Forkers

tbnomoney

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.