Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mishushakov/dialogflow-gateway-js
🔌 Dialogflow V2 JS SDK for node and browser
https://github.com/mishushakov/dialogflow-gateway-js
client dialogflow dialogflow-v2 nlu
Last synced: 4 days ago
JSON representation
🔌 Dialogflow V2 JS SDK for node and browser
- Host: GitHub
- URL: https://github.com/mishushakov/dialogflow-gateway-js
- Owner: mishushakov
- License: mit
- Created: 2019-04-18T10:02:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-14T16:49:21.000Z (over 1 year ago)
- Last Synced: 2024-09-04T17:29:31.959Z (about 1 month ago)
- Topics: client, dialogflow, dialogflow-v2, nlu
- Language: TypeScript
- Homepage: https://npmjs.com/package/dialogflow-gateway
- Size: 516 KB
- Stars: 6
- Watchers: 2
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dialogflow Gateway JavaScript SDK
Dialogflow Gateway enables third-party integrations to securely access the Dialogflow V2 API
- [Documentation](https://github.com/mishushakov/dialogflow-gateway-docs)
- [Implementations](https://github.com/mishushakov/dialogflow-gateway-docs#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:
```html
```
## Usage
Import the library and connect to your Dialogflow Gateway Endpoint:
```js
import { Client } from 'dialogflow-gateway'new Client('')
```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](https://dialogflow.cloud.ushakov.co)
```js
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
```js
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
```js
/* 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](./examples)