From 94999a1a96b2e8cb8eff8401b885ed2d2585ebb4 Mon Sep 17 00:00:00 2001 From: khanh Date: Sun, 7 Jul 2024 03:18:42 +0700 Subject: [PATCH] added action goto --- Constant.js | 1 + actions/Goto.js | 26 ++++++++++++++++++++++++++ actions/Main.js | 6 +++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 actions/Goto.js diff --git a/Constant.js b/Constant.js index 2677ebc..06cd42c 100644 --- a/Constant.js +++ b/Constant.js @@ -8,4 +8,5 @@ module.exports = { SET_DATA: "SET_DATA", SUB_FLOW: "SUB_FLOW", SEND_MAIL: "SEND_MAIL", + GO_TO: "GO_TO" }; diff --git a/actions/Goto.js b/actions/Goto.js new file mode 100644 index 0000000..00400d8 --- /dev/null +++ b/actions/Goto.js @@ -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, +}; diff --git a/actions/Main.js b/actions/Main.js index 3686f20..f5379c1 100644 --- a/actions/Main.js +++ b/actions/Main.js @@ -13,6 +13,7 @@ const { SUB_FLOW, CHECK_VARIABLE, SEND_MAIL, + GO_TO, } = require('../Constant'); const { getFlowByContactId } = require('../services/proxy'); @@ -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'; @@ -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)]) @@ -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]) {