voxa
Version:
A fsm (state machine) framework for Alexa, Dialogflow, Facebook Messenger and Botframework apps using Node.js
34 lines (26 loc) • 899 B
text/typescript
import { DialogflowConversation } from "actions-on-google";
import * as _ from "lodash";
import { IVoxaIntent } from "../../VoxaEvent";
export class DialogflowIntent implements IVoxaIntent {
public name: string;
public params: any;
public rawIntent: DialogflowConversation;
constructor(conv: DialogflowConversation) {
this.rawIntent = conv;
this.name = conv.action;
if (!this.name || this.name === "input.unknown") {
this.name = conv.intent;
}
this.name = this.name.replace(/^AMAZON./, "");
this.params = this.getParams();
}
private getParams(): any {
const args = this.rawIntent.arguments.parsed.input;
const input: any = {};
if (this.rawIntent.input.type) {
input[this.rawIntent.input.type] = this.rawIntent.input.raw;
}
const parameters = this.rawIntent.parameters;
return _.merge({}, args, input, parameters);
}
}