Skip to content
🔌 Dialogflow V2 JS SDK for node and browser
JavaScript TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build Updated Jul 29, 2019
test
.gitignore Initial Commit Apr 18, 2019
LICENSE Initial Commit Apr 18, 2019
README.md Updated Jul 29, 2019
index.js
index.ts Updated Jul 29, 2019
package.json v0.0.4 Jul 29, 2019
tsconfig.json Separated Browser from Node Apr 18, 2019
webpack.config.js
yarn.lock

README.md

Dialogflow Gateway JavaScript SDK

Dialogflow Gateway enables third-party integrations to securely access the Dialogflow V2 API

This is a JavaScript Client, that is compatitable with Dialogflow Gateway backends. It can be used both in browser and node as a drop-in 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

Import the library and connect to your Dialogflow Gateway Endpoint:

import { Client } from 'dialogflow-gateway'

new Client('<YOUR ENDPOINT HERE>').connect()

Examples

With Async/Await and ES Modules on Dialogflow Gateway Hosted by Ushakov

import { Client } from 'dialogflow-gateway'

async () => {
    /* Connecting Dialogflow Gateway Client */
    let client = await new Client('https://dialogflow-web-v2.gateway.dialogflow.cloud.ushakov.co').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 with require and promises

const { Client } = require('dialogflow-gateway')

/* Connecting Dialogflow Gateway Client */
new Client('https://dialogflow-web-v2.gateway.dialogflow.cloud.ushakov.co').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('https://dialogflow-web-v2.gateway.dialogflow.cloud.ushakov.co').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))
})
You can’t perform that action at this time.