dialogflow-api-utils
v0.5.3
Published
Utility lib for working with the Dialogflow (formerly api.ai) API response data
Downloads
4
Readme
dialogflow-api-utils
Utility lib for working with Dialogflow (formerly api.ai) API response data
Installation
- Requires Api.ai/Dialogflow SDK or similar to get data from Dialogflow (formerly api.ai)
- Install module with
npm
:
npm install --save dialogflow-api-utils
Usage
Below is an example how to use the module along with the api
module.
const apiai = require('apiai');
// Utilities for v1 of the Dialogflow API
const dfUtils = require('dialogflow-api-utils').v1;
const app = apiai("<your client access token>");
var request = app.textRequest('<Your text query>', {
sessionId: '<unique session id>'
});
request.on('response', function(response) {
// get all the parameters
var params = dfUtils.Query.getResultParameters(response);
// get the value of parameter 'foo', if it isn't set, the return 'bar'
var fooParam = dfUtils.Query.getResultParameter(response, 'foo', 'bar');
// get all the messages from fulfillment
var messages = dfUtils.Query.getFulfillmentMessages(response);
// only get the messages for Facebook Messenger
var fbMessages = dfUtils.Query.getFulfillmentMessages(response, 'facebook');
// only get the messages for Slack
var slackMessages = dfUtils.Query.getFulfillmentMessages(response, 'slack');
// get the context 'userProfile'
var userProfileContext = dfUtils.Query.getResponseContext(response, 'userProfile');
// code to send messages
});
request.on('error', function(error) {
console.log(error);
});
request.end();
Documentation
View documentation for an overview of all functions and their parameters
License
See LICENSE.