Code Monkey home page Code Monkey logo

dialogflow-gateway-js's Introduction

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))
})

dialogflow-gateway-js's People

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.