Skip to content

smalltalk-ai/dialogflow-fulfillment-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dialogflow-fulfillment-utils

npm

Utility lib for handling Dialogflow v2 API detectIntent Response object's filfillment object

Installation

  • Requires Dialogflow SDK or similar
  • Install module with npm:
npm install --save dialogflow-fulfillment-utils

Usage

Below is an example how to use the module along with the api module.

const dialogflow = require('dialogflow');
const uuid = require('uuid');
const dffUtils = require('dialogflow-fulfillment-utils');

/**
 * Send a query to the dialogflow agent, and return the query result.
 * @param {string} projectId The project to be used
 */
async function runSample(projectId = 'your-project-id') {
  // A unique identifier for the given session
  const sessionId = uuid.v4();
 
  // Create a new session
  const sessionClient = new dialogflow.SessionsClient();
  const sessionPath = sessionClient.sessionPath(projectId, sessionId);
 
  // The text query request.
  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        // The query to send to the dialogflow agent
        text: 'hello',
        // The language used by the client (en-US)
        languageCode: 'en-US',
      },
    },
  };
 
  // Send request and log result
  const responses = await sessionClient.detectIntent(request);

  // get all the messages from fulfillment
  var messages = dffUtils.getMessages(responses);
  // only get the messages for Facebook Messenger
  var fbMessages = dffUtils.getMessages(responses, 'facebook');
  // only get the messages for Slack
  var slackMessages = dffUtils.getMessages(responses, 'slack');

}

Documentation

View documentation for an overview of all functions and their parameters

License

See LICENSE.

About

Utilities for working with Dialogflow fulfillment messages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published