Skip to content

dtesler/node-api.ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api.ai (node.js)

This plugin allows the integration of agents from the api.ai natural language processing service with your Node.js application.

Installation

  npm install --save api.ai

Usage

Initializing the module

Your client access token can be obtained in your Dashboard.

const apiai = require("api.ai");

const nlp = new apiai({
  token: "<your client access token>",
  session: "<unique session id>"
});

Handling responses

This module supports both callbacks and promises to deliver your data.

Callbacks:
nlp.text("Hello World!", function (error, response) {
  if (error) {
    // Handle Error
  }
  else {
    // Do what you wish with response
  }
});
Promises:
nlp.text("Hello World!")
.then(function (response) {
  // Do what you wish with response
})
.error(function (error) {
  // Handle error
});

Making requests

This module supports making 3 different types of requests to api.ai:

  • Text requests
  • Voice requests
  • User entities requests
Text requests

These are the simplest of the above. Simply send text to api.ai to be processed:

nlp.text("Hello World", callback);
Voice requests

To send a voice request, you may either provide a buffer or the path of an audio file:

nlp.voice("hello_world.wav", callback);

You may also specify additional options, for instance - language:

nlp.voice("hello_world.wav", {
  language: "en"
}, callback);
User Entity requests
nlp.userEntities(user_entities, callback);

This module was created by David Tesler, using the original Node.JS SDK for api.ai

Awesomeness supplied by api.ai.

Releases

No releases published

Packages

No packages published