npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dialogflow-gateway

v1.0.1

Published

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

Downloads

8

Readme

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