voxa
Version:
A fsm (state machine) framework for Alexa, Dialogflow, Facebook Messenger and Botframework apps using Node.js
23 lines (20 loc) • 765 B
text/typescript
import { ITransition } from "../StateMachine";
import { VoxaApp } from "../VoxaApp";
import { IVoxaEvent } from "../VoxaEvent";
import { IVoxaReply } from "../VoxaReply";
export function register(skill: VoxaApp) {
skill.onRequestStarted((voxaEvent: IVoxaEvent) => {
const fromState = voxaEvent.session.new
? "entry"
: voxaEvent.session.attributes.state || "entry";
voxaEvent.session.outputAttributes.flow = [fromState];
});
skill.onAfterStateChanged(
(voxaEvent: IVoxaEvent, reply: IVoxaReply, transition: ITransition) => {
voxaEvent.session.outputAttributes.flow =
voxaEvent.session.outputAttributes.flow || [];
voxaEvent.session.outputAttributes.flow.push(transition.to);
return transition;
},
);
}