This is a fork of the official Node.js client for Api.ai - where we have added the ability to work with intents (create, udpate, list and remove). Note that this fork requires the developer token as well - it's also suitable for other Api.ai objects that work with the developer token.
- Install Node.js
- Install Api.ai SDK with
npm
:
npm install apiai
- Create
main.js
file with the following code:
var apiai = require('apiai');
var app = apiai("<your client access token>", "<your developer access token>");
function ask(text, options) {
return new Promise((resolve, reject) => {
var defaultOptions = {
sessionId: '<unique session id>', // use any arbitrary id - doesn't matter
};
let request = app.textRequest(text, Object.assign(defaultOptions, options));
request.on('response', (response) => {
return resolve(response);
});
request.on('error', (error) => {
return reject(error);
});
request.end();
})
}
function getAllIntents(options) {
return new Promise((resolve, reject) => {
let request = app.intentGetRequest(options);
request.on('response', (response) => {
return resolve(response);
});
request.on('error', (error) => {
return reject(error);
});
request.end();
})
}
// ask something
ask('<Your text query>')
.then(response => {
console.log(response);
}).catch(error => {
console.log(error)
});
// get list of all intents
getAllIntents()
.then(intents => {
console.log(intents);
}).catch(error => {
console.log(error)
});
- Run following command.
node main.js
- Your can find more examples in
samples
directory.