Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adrien2p/nestjs-dialogflow
Dialog flow module that simplify the web hook handling for your NLP application using NestJS :satellite:
https://github.com/adrien2p/nestjs-dialogflow
addons dialogflow google-dialogflow nestjs nlp typescript webhook
Last synced: about 6 hours ago
JSON representation
Dialog flow module that simplify the web hook handling for your NLP application using NestJS :satellite:
- Host: GitHub
- URL: https://github.com/adrien2p/nestjs-dialogflow
- Owner: adrien2p
- License: mit
- Created: 2018-05-07T19:28:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-21T07:39:47.000Z (about 2 months ago)
- Last Synced: 2024-10-30T20:05:30.319Z (14 days ago)
- Topics: addons, dialogflow, google-dialogflow, nestjs, nlp, typescript, webhook
- Language: TypeScript
- Size: 2 MB
- Stars: 72
- Watchers: 3
- Forks: 14
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-nestjs - Nestjs Dialogflow - Dialog 流模块,使用 NestJS 简化 NLP 应用程序的 Web 钩子处理。 (资源 / 组件和库)
README
[![Build Status](https://travis-ci.org/adrien2p/nestjs-dialogflow.svg?branch=master)](https://travis-ci.org/adrien2p/nestjs-dialogflow.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/adrien2p/nestjs-dialogflow/badge.svg?branch=master)](https://coveralls.io/github/adrien2p/nestjs-dialogflow?branch=master)
[![npm version](https://badge.fury.io/js/nestjs-dialogflow.svg)](https://badge.fury.io/js/nestjs-dialogflow)
[![npm](https://img.shields.io/npm/dm/nestjs-dialogflow.svg)](https://badge.fury.io/js/nestjs-dialogflow)
[![Known Vulnerabilities](https://snyk.io/test/github/adrien2p/nestjs-dialogflow:package.json/badge.svg?targetFile=package.json)](https://snyk.io/test/github/adrien2p/nestjs-dialogflow:package.json?targetFile=package.json)# DialogFlow module for NestJS :satellite:
Dialog flow module that simplify the web hook handling for your NLP application using NestJS
## Getting Started
To start using this module you should run the following command
`npm i nestjs-dialogflow @nestjs/common @nestjs/core reflect-metadata`
### Features
There are 3 decorators provided by the module that allow you to handle intent/action or pick properties from the response.
| Name | behavior |
|:-----|:--------:|
|`@DialogFlowIntent('myIntent')`
`public method(param: DialogFlowResponse)`| Handle the specified intent into the decorated method |
|`@DialogFlowAction('myAction')`
`public method(param: DialogFlowResponse)`| Handle the specified action into the decorated method |
|`@DialogFlowIntent('myIntent')`
`public method(@DialogFlowParam('queryResult') param: QueryResult)`| Get the value of the property specified through the parameter decorator |### Set up
To use the module, you have to import it into your `ApplicationModule` and call the `forRoot` in order
to initialize the module. The `forRoot` method can take as parameters an object with a `basePath` and a `postPath`
in order to configure the controller used for the web hook.```ts
@Module({
imports: [
DialogFlowModule.forRoot({
basePath: 'web-hooks',
postPath: 'dialog-flow'
})
]
})
export class ApplicationModule { }
```After that, you have to go to your dialogFlow account to set up the url that should be reach to provide the result of
your NLP request into the `Fulfillment` section of your agent. The url with the default config should looks like `https://myurl.me/web-hooks/dialog-flow`To handle an intent, you have to create your own Injectable that will implement all the methods needed in order to handle
the concerned intents/action.```ts
@Injectable()
export class MyDialogFlowProvider {
@DialogFlowIntent('My:intent1')
public async handleMyIntent1(dialogFlowResponse: DialogFlowResponse): Promise {
/* Your code here */
return {} as DialogFlowFulfillmentResponse;
}@DialogFlowIntent('My:intent2')
public async handleMyIntent2(dialogFlowResponse: DialogFlowResponse): Promise {
/* Your code here */
return {} as DialogFlowFulfillmentResponse;
}
}
```You also have the possibility to pick any properties that you need directly from the `dialogFlowResponse`, to get them from
the handler parameters. To do that, you can use the `@DialogFlowParam` decorator and pass as parameter a string path to
the property that you want to pick.```ts
@Injectable()
export class MyDialogFlowProvider {
@DialogFlowIntent('My:intent1')
public async handleMyIntent1(@DialogFlowParam('queryResult.outputContexts') outputContexts: OutputContexts): Promise {
/* Your code here */
return {} as DialogFlowFulfillmentResponse;
}@DialogFlowIntent('My:intent2')
public async handleMyIntent2(@DialogFlowParam('queryResult') queryResult: QueryResult): Promise {
/* Your code here */
return {} as DialogFlowFulfillmentResponse;
}
}
```Inside the `DialogFlowModule` a middleware is apply in order to validate the token sent by `dialogFlow`, so when your start
your server, you will have to set the `DIALOG_FLOW_AUTHORIZATION_TOKEN` env variable.That's it, you can run your application and test it !! :)
## Built With
* [NestJS](https://github.com/nestjs/nest) A progressive Node.js framework for building efficient and scalable server-side applications on top of TypeScript & JavaScript (ES6 / ES7 / ES8) heavily inspired by Angular
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/adrien2p/nestjs-dialogflow/tags).
## Authors
* **Adrien de Peretti**
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details