0.5.3 • Published 5 years ago

dialogflow-api-utils v0.5.3

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

dialogflow-api-utils

npm

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.

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

6 years ago

0.5.0

6 years ago