Skip to content

Commit

Permalink
added action goto
Browse files Browse the repository at this point in the history
  • Loading branch information
khanh1902 committed Jul 6, 2024
1 parent 5ac3e4e commit 94999a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions Constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = {
SET_DATA: "SET_DATA",
SUB_FLOW: "SUB_FLOW",
SEND_MAIL: "SEND_MAIL",
GO_TO: "GO_TO"
};
26 changes: 26 additions & 0 deletions actions/Goto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { ComponentDialog, WaterfallDialog } = require('botbuilder-dialogs');
const { GO_TO } = require('../Constant');

const GOTOACTION_WATERFALL = 'GOTOACTION_WATERFALL';

class GotoAction extends ComponentDialog {
constructor(dialog) {
super(GO_TO);
this.dialog = dialog;
this.addDialog(
new WaterfallDialog(GOTOACTION_WATERFALL, [
this.goto.bind(this),
])
);
this.initialDialogId = GOTOACTION_WATERFALL;
}

async goto(step) {
const { gotoId } = step.step._info.options;
return await step.endDialog({ actionId: gotoId });
}
}

module.exports = {
GotoAction,
};
6 changes: 5 additions & 1 deletion actions/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
SUB_FLOW,
CHECK_VARIABLE,
SEND_MAIL,
GO_TO,
} = require('../Constant');

const { getFlowByContactId } = require('../services/proxy');
Expand All @@ -28,6 +29,7 @@ const { HttpRequest } = require('./HTTPRequest');
const { SubFlow } = require('./SubFlow');
const { CheckVariable } = require('./CheckVariable');
const { SendMail } = require('./SendMail');
const { GotoAction } = require('./Goto');

const CHAT = 'CHAT';

Expand All @@ -48,6 +50,7 @@ class MainDialog extends ComponentDialog {
this.addDialog(new SubFlow(this));
this.addDialog(new CheckVariable(this));
this.addDialog(new SendMail(this));
this.addDialog(new GotoAction(this))

this.addDialog(
new WaterfallDialog('Main_Water_Fall', [this.ReadFlow.bind(this)])
Expand Down Expand Up @@ -186,12 +189,13 @@ class MainDialog extends ComponentDialog {
const { action } = step._info.options;

const actions = {
message: SEND_TEXT,
'message': SEND_TEXT,
'prompt-and-collect': PROMPTING,
'http-request': HTTP_REQUEST,
'sub-flow': SUB_FLOW,
'check-variables': CHECK_VARIABLE,
'send-mail': SEND_MAIL,
'goto"': GO_TO
};

if (!actions[action]) {
Expand Down

0 comments on commit 94999a1

Please sign in to comment.