You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

dialogflow-api-utils

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dialogflow-api-utils

Utility lib for working with the Dialogflow (formerly api.ai) API response data

0.5.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

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.

Keywords

api.ai

FAQs

Package last updated on 06 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts