npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dialogflow-webhook-parser

v1.0.5

Published

A simple dialogflow parser created that simplifies handling response format with additional features. See readme file for more detail

Downloads

12

Readme

Dialogflow Webhook Response Parser

Abstracts the format for sending response to Dialogflow


Steps to follow:

  1. Install the package using following command:
    npm i dialogflow-webhook-parser
  2. This module needs an object of messages if we need to override default dialogflow response. This message object will be a key-value pair where value will be fetched for respective key mentioned while overriding dialogflow response. (Find all the formats below that it needs)
  3. Import the package using following command
    const agent = require('dialogflow-webhook-parser').agent;
  4. After you import the package, you need to configure the module by sending message object as an argument. You can view all formats required at the bottom of document. agent.config(MessageObject);
  5. Now you can utilize the package to perform following actions:
    • Trigger an intent forcefully
    • Override dialogflow response completely
    • Provide selective text boxes from multiple dialogflow response lists
    • Set a context
    • Send custom payload
    • Provide suggestions (Actions on Google)
  6. Let's see how we can perform each of the above tasks

Agent Methods:

  • Config Method:
agent.config(MessageObject);
Return value: -  
  • Send Method:
agent.send(request, rawObject);
Return value: ResponseObject 

How to:

  • Trigger an intent forcefully
const triggerObj = {
    trigger: eventName, // Here eventName is event defined in Dialogflow console for an intent
}
return agent.send(request, triggerObj);
  • Override dialogflow response completely
const MessageObj = {
    "name": ["What is your name?"]
}
agent.config(MessageObject);
const overrideObj = {
    "message": "name", // *name* is the key in MessageObj
}
return agent.send(request, overrideObj);
  • Provide selective text boxes from multiple dialogflow response lists
const filterObj = {
    filterDialoglowResponseList: [0,1,4] // Here, 0,1,4 are indexes of text responses defined in Dialogflow for an intent
}
return agent.send(request, filterObj);
  • Set a context
const contextObj = {
    contextList: [{ name: 'test', lifespan: '2' }] // This will set the context test active for next query in dialogflow. Here, lifespan parameter is optional. By default, it will set lifespan as 1.
}
return agent.send(request, contextObj);
  • Send custom payload
const payloadObj = {
    customPayloadParams: "{JSON Object}" // Stringified JSON object or any plain text 
}
return agent.send(request, payloadObj);
  • Send suggestions
const suggestionsObj = {
    suggestions: ['Suggestion 1','Suggestion 2', 'Suggestion 3'];
}
return agent.send(request, suggestionsObj);

Formats/Schema

Following schema is used to store all the messages at one place that we would be overriding from dialogflow. So, once we need to override, we can pass the key in message atrribute and it will fetch the response from MessageObject and override the dialogflow response

Schema:

MessageObject = {
    "key": ["value1","value2"]
}

Example:

const a = require('dialogflow-webhook-parser').agent;

MessageObject = {
    "name": ["What is your name"],
    "email": ["What is your email"]
}

agent.config(MessageObject);

request Object: This contains the request object we get from Dialogflow Schema:

{
  "responseId": "",
  "queryResult": {
    "queryText": "",
    "parameters": {
      "CampusOfInterest": "",
      "DegreeOfInterest": "",
      "Specialization": "",
      "ProgramOfInterest": "",
      "Country": "",
      "State": ""
    },
    "allRequiredParamsPresent": ,
    "fulfillmentText": "",
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            ""
          ]
        }
      }
    ],
    "intent": {
      "name": "",
      "displayName": ""
    },
    "intentDetectionConfidence": ,
    "languageCode": "en"
  },
  "originalDetectIntentRequest": {
    "payload": {}
  },
  "session": ""
}

rawObject: This contains custom object that tells the package to perform respective actions

Various attributes it supports are:

  • trigger: Used to trigger an intent from webhook into Dialogflow changing the flow of conversation
  • message: Used to override the default dialogflow response using MessageObject that was configured
  • contextList: Used to set context from webhook in dialogflow
  • suggestions: Used to provide suggestions to user from webhook (Actions on Google)
  • customPayloadParams: Used to provide custom payload response from webhook

ResponseObject: This is processed response that we get as a result. This can be directly sent as a resposne to dialogflow Schema:

{
    "fulfillmentMessages": [
        {
            "text": {
                "text": []
            }
        },
        {
            "platform": "ACTIONS_ON_GOOGLE",
            "suggestions": {
                "suggestions": [
                    {
                        "title": ""
                    },
                    {
                        "title": ""
                    }
                ]
            }
        }
    ],
    "fulfillmentText": "",
    "outputContexts": [
        {
            "name": "",
            "lifespanCount": 1
        },
        {
            "name": "",
            "lifespanCount": 1
        },
        {
            "name": "",
            "lifespanCount": 1,
            "parameters": {}
        }
    ]
}