Coder Social home page Coder Social logo

mockflow's Introduction

Mockflow

Mockflow lets you send mock requests to your Dialogflow fulfillment code, for offline unit testing.

Installation

The following command will install the mockflow package to your project:

npm install mockflow

The Basics

Connect to your fulfillment code and send a mock intent request

const Mockflow = require('mockflow');
// Import the Firebase Functions code for your Dialogflow Fulfillment Webhook
// This assumes that the file is in the same directory as index.js - change as necessary
const app = require('.');

// Initialize Mockflow with your Dialogflow project's name and the webhook handler
// Change app.handler if you exported your handler with a custom name
const mock = new Mockflow('my-voice-app', app.handler);

// Send an intent request and check results
it("Enter a description of what should happen here", async function () {
    let result = await mock.intent('My Intent Name').send()
    
    // Provide the result and a string array with keywords/phrases to look for in in the response
    return mock.existsAndMatches(result, ['words','to','look for'])
});

Further customization

The above example creates a simple intent request using sensible defaults for Dialogflow's many parameters. However, you can use the request builder's with...() methods to set the other parameters.

it("Should respond by saying that my favorite color is blue", async function () {
    // Send an intent request
    let result = await mock.intent('Favorite Color Intent')
        .withParameter('Color', 'blue')
        .withQueryText('i like blue')
        .send()

    return mock.existsAndMatches(result, ['favorite','color','blue'])
});

Available Overrides

  • withQueryText(queryText)
  • withParameter(name, value)
  • withAllRequiredParamsPresent(allRequiredParamsPresent)
  • withFulfillmentText(fulfillmentText)
  • withFulfillmentMessage(fulfillmentMessage)
  • withOutputContext(outputContext)
  • withIntentDetectionConfidence(intentDetectionConfidence)
  • withDiagnosticInfo(name, value)
  • withLanguageCode(languageCode)
  • withOriginalDetectIntentRequest(originalDetectIntentRequest)

Limitations

  • Only Dialogflow v2 fulfillments are supported. v1 has not been tested and probably won't work.

mockflow's People

Contributors

carterkwon avatar sodle avatar

Watchers

James Cloos avatar

Forkers

bidchatbot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.