You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const{handleFormAction}=require('nodejs-formaction-sdk-rasa');constrequest=req.body;// from express endpoint in external nodejs actions endpointconstrequired_slot=['origin','destination','date'];constentites=request.tracker.latest_message.entities;constslots=request.tracker.slots;consttemplates=request.domain.templates;constnextAction='utter_flight_details';constsenderID=request.sender_id;//SenderID is used to send out random unrepeating utterance if multiple utterance available. Optional feature to enhance user experience constformHandle=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
"use strict";const{handleFormAction}=require('nodejs-formaction-sdk-rasa');constexpress=require('express');constapp=express();constport=3001;app.use(express.json({limit: '5mb'}));app.post('/actionWebhook',(req,res)=>{constrequest=req.body;constnext_action=request.next_action;constentities=request.tracker.latest_message.entities;constslots=request.tracker.slots;constsender=request.sender_id;constrequired_slots=['origin','destination','flight_class','num_people','date'];constnextAction='utter_flight_details';letformAction;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_<SLOT_NAME> 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.