Nonlinear Performance Magnification

npm

Need private packages and team management tools?Check out npm Orgs. »

dialogflow-gateway

0.0.3 • Public • Published

Dialogflow Gateway JavaScript SDK

Dialogflow Gateway is a cloud-based service, which connects Dialogflow V2 Agents to the World Wide Web

This is the Official Dialogflow Gateway JavaScript Client. It can be used both in browser and node as a replacement for the deprecated dialogflow-javascript-client library, by @dialogflow

⚡️ Blazing-fast and super-small (<10KB)

Installation

npm:

npm install dialogflow-gateway

Yarn:

yarn add dialogflow-gateway

Browser:

<script src="https://unpkg.com/dialogflow-gateway@latest/build/bundle.js"></script>

Usage

Link your Agent to Dialogflow Gateway, you can find a detailed guide here

Then, import the library and connect client to your Gateway:

import { Client } from 'dialogflow-gateway'
 
new Client('<YOUR GOOGLE PROJECT ID HERE>').connect()

Examples

With Async/Await and ES Modules

import { Client } from 'dialogflow-gateway'
 
async () => {
    /* Connecting Dialogflow Gateway Client */
    let client = await new Client('dialogflow-web-v2').connect()
 
    /* Making Text request */
    let response = await client.request({
        session: 'test',
        queryInput: {
            text: {
                text: "Hello",
                languageCode: "en"
            }
        }
    })
 
    console.log(response)
 
    /* Getting Agent information */
    console.log(await client.get())
}

Same code in NodeJS (with require and promises)

let { Client } = require('dialogflow-gateway')
 
/* Connecting Dialogflow Gateway Client */
new Client('dialogflow-web-v2').connect()
.then(client => {
    /* Making Text request */
    client.request({
        session: 'test',
        queryInput: {
            text: {
                text: "Hello",
                languageCode: "en"
            }
        }
    })
    .then(response => console.log(response))
 
    /* Getting Agent information */
    client.get().then(agent => console.log(agent))
})

Same code in Browser. Notice, that we are using the df scope

/* Connecting Dialogflow Gateway Client */
new df.Client('dialogflow-web-v2').connect()
.then(client => {
    /* Making Text request */
    client.request({
        session: 'test',
        queryInput: {
            text: {
                text: "Hello",
                languageCode: "en"
            }
        }
    })
    .then(response => console.log(response))
 
    /* Getting Agent information */
    client.get().then(agent => console.log(agent))
})

install

npm i dialogflow-gateway

Downloadsweekly downloads

22

version

0.0.3

license

MIT

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability