1.0.1 • Published 3 years ago

dialogflow-gateway v1.0.1

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

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

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

1.0.1

3 years ago

1.0.0

3 years ago

0.1.0

4 years ago

0.0.8

4 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago