Socket
Socket
Sign inDemoInstall

dialogflow-gateway

Package Overview
Dependencies
14
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dialogflow-gateway

Dialogflow V2 JS SDK for node and browser. Written in TypeScript


Version published
Maintainers
1
Install size
720 kB
Created

Readme

Source

Dialogflow Gateway JavaScript SDK

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

  • Documentation
  • Implementations

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

Attention: v1.0 is no longer using promises to retrieve messages and relies on events instead

Installation

npm:

npm install dialogflow-gateway

yarn:

yarn add dialogflow-gateway

Browser:

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

Usage

Import the library and connect to your Dialogflow Gateway Endpoint:

import { Client } from 'dialogflow-gateway'

new Client('<YOUR ENDPOINT HERE>')

Note: Endpoint is a URL (example: https://dialogflow-web-v2.core.ushaflow.io)

Events

  • error, returns error
  • message, returns the message body

Examples

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

import { Client } from 'dialogflow-gateway'

async () => {
  /* Connect Dialogflow Gateway Client */
  const client = new Client('https://dialogflow-web-v2.core.ushaflow.io')

  /* Send text request */
  await client.send({
    session: 'test',
    queryInput: {
      text: {
        text: 'Hello',
        languageCode: 'en'
      }
    }
  })

  client.on('message', console.log)
  client.error('message', console.error)

  /* Retrieve the Agent */
  try {
    const agent = await client.get())
    console.log(agent)
  }

  catch (error){
    // Handle error
  }
}

Same code with require and promises

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

/* Connect Dialogflow Gateway Client */
const client = new Client('https://dialogflow-web-v2.core.ushaflow.io')

/* Send text request */
client.send({
  session: 'test',
  queryInput: {
    text: {
      text: 'Hello',
      languageCode: 'en'
    }
  }
})

client.on('message', console.log)
client.error('message', console.error)

/* Retrieve the Agent */
client.get()
.then(agent => {
  console.log(agent)
})
.catch(error => {
  // Handle Error
})

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

/* Connect Dialogflow Gateway Client */
const client = new df.Client('https://dialogflow-web-v2.core.ushaflow.io')

/* Send text request */
client.send({
  session: 'test',
  queryInput: {
    text: {
      text: 'Hello',
      languageCode: 'en'
    }
  }
})

client.on('message', console.log)
client.error('message', console.error)

/* Retrieve the Agent */
client.get()
.then(agent => {
  console.log(agent)
})
.catch(error => {
  // Handle Error
})

For more examples see examples directory

Keywords

FAQs

Last updated on 10 Aug 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc