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

@machinat/dialogflow

v0.6.0

Published

This module implement the [`IntentRecognizer`](https://machinat.com/api/modules/core_base_intentrecognizer.html) interface with [DialogFlow ES](https://cloud.google.com/dialogflow/es/docs) API.

Downloads

18

Readme

DialogFlow Module

This module implement the IntentRecognizer interface with DialogFlow ES API.

Install

npm install @machinat/core @machinat/dialogflow
# or with yarn
yarn add @machinat/core @machinat/dialogflow

Docs

Check the Recognizing Intent document and the API references.

Setup

You can use this module in two different modes:

Delegated Mode

In this mode, the DialogFlow project is managed by the package. You maintain the training data along with the codes, and delegate the configuring procedures to the package.

First you need to create a GCP project and a service account to access the API. Follow this guide and set the GOOGLE_APPLICATION_CREDENTIALS environment variable when running your app.

Then add @machinat/dialogflow module like this:

import Machinat from '@machinat/core';
import DialogFlow from '@machinat/dialogflow';

const app = Machinat.createApp({
  modules: [
    DialogFlow.initModule({
      projectId: '_YOUR_DIALOGFLOW_PROJECT_ID_',
      recognitionData: {
        defaultLanguage: 'en',
        languages: ['en'],
        intents: {
          greeting: {
            trainingPhrases: {
              en: ['hello', 'hi']
            }
          }
        },
      },
    }),
  ],
});

Finally you have to call DialogFlowRecognizer.train() method every time you update the intents data. Like:

// cli/updateDialogFlow.js
import Machinat from '@machinat/core';
import DialogFlow from '@machinat/dialogflow';

const app = Machinat.createApp({/* ... */});
app
  .start()
  .then(() => {
    const [recognizer] = app.useServices([DialogFlow.Recognizer]);
    return recognizer.train();
  });

It's recommended to run this every time you deploy a new version of your app. It'll not retrain if the intents data remain the same, so it's really cheap to call.

Manual Mode

In this mode, you have to manage the DialogFlow project on your own. The package only works as a client for detecting intents.

First you have to prepare a ready-to-use DialogFlow agent. You can follow this guide to create one and add the intents in the DialogFlow console.

Next follow this section to create a service account and set the GOOGLE_APPLICATION_CREDENTIALS environment variable.

Then add @machinat/dialogflow module like this:

import Machinat from '@machinat/core';
import DialogFlow from '@machinat/dialogflow';

const app = Machinat.createApp({
  modules: [
    DialogFlow.initModule({
      projectId: '_YOUR_DIALOGFLOW_PROJECT_ID_',
      // prevent package to edit the project
      manualMode: true,
      // detect intent with the default agent in dev
      useDefaultAgent: process.env.NODE_ENV !== 'production',
      // specify the environment to be used on production
      environment: 'production',
      recognitionData: {
        defaultLanguage: 'en',
        languages: ['en'],
        intents: {},
      },
    }),
  ],
});

If you call DialogFlowRecognizer.train() method under manual mode, it creates a snapshot version on the environment. You can do it every time you deploy a new version of app, so the DialogFlow agent would have a revertible version along with the version of app.