https://github.com/rohitnairtech/nodejs-formaction-sdk-rasa
FormAction SDK written in NodeJS for Rasa - https://rasa.com/docs/rasa/
https://github.com/rohitnairtech/nodejs-formaction-sdk-rasa
Last synced: 6 months ago
JSON representation
FormAction SDK written in NodeJS for Rasa - https://rasa.com/docs/rasa/
- Host: GitHub
- URL: https://github.com/rohitnairtech/nodejs-formaction-sdk-rasa
- Owner: rohitnairtech
- Created: 2020-03-03T03:42:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-09T02:36:10.000Z (almost 4 years ago)
- Last Synced: 2024-10-13T13:19:22.992Z (8 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/nodejs-formaction-sdk-rasa
- Size: 9.77 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README



# FormAction SDK for Rasa
## Installation
```
npm i nodejs-formaction-sdk-rasa
```
### OR
```
npm i https://github.com/rohitnairtech/nodejs-formaction-sdk-rasa/tarball/master
```
## Usage```javascript
const {handleFormAction} = require('nodejs-formaction-sdk-rasa');
handleFormAction(, , , , , );
```
### OR```javascript
const formAction = require('nodejs-formaction-sdk-rasa');
formAction.handleFormAction(, , , , , );
```## FormAction example
```javascript
const {handleFormAction} = require('nodejs-formaction-sdk-rasa');const request = req.body; // from express endpoint in external nodejs actions endpoint
const required_slot = ['origin', 'destination', 'date'];
const entites = request.tracker.latest_message.entities;
const slots = request.tracker.slots;
const templates = request.domain.templates;
const nextAction = 'utter_flight_details';
const senderID = request.sender_id;
//SenderID is used to send out random unrepeating utterance if multiple utterance available. Optional feature to enhance user experienceconst formHandle = handleFormAction(required_slot, entities, slots, templates, nextAction, senderID);
formHandle.then(resp=>{
console.log(resp);
//send the response back to rasa python agent
}).catch(err=>{
console.log(err);
});
```## FormAction example, using expressjs as webserver
```javascript
"use strict";const {handleFormAction} = require('nodejs-formaction-sdk-rasa');
const express = require('express');
const app = express();
const port = 3001;app.use(express.json({limit: '5mb'}));
app.post('/actionWebhook', (req, res) => {
const request = req.body;
const next_action = request.next_action;
const entities = request.tracker.latest_message.entities;
const slots = request.tracker.slots;
const sender = request.sender_id;
const required_slots = ['origin', 'destination', 'flight_class', 'num_people', 'date'];
const nextAction = 'utter_flight_details';let formAction;
switch(next_action){
case 'form_name':
formAction = handleFormAction(required_slots, entities, slots, nextAction, sender);
formAction.then(resp=>{
res.json(resp);
}).catch(err=>{
console.log(err);
});
break;
}});
app.listen(port, () => console.log(`Actions server listening on port ${port}`));
```
## Notes
- TURN OFF AUTOFILL for SLOTS in domain, but use the same name as the ENTITIES for SLOTS - SlotFilling happens in the module
- Register utter_ask_ this is used to dynamically utter a question back to the user.
- Register nextAction name - utterance/custom action name in domain. That action will called upon successfully completing slot filling.