botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
83 lines • 3.87 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RepeatDialog = void 0;
/**
* @module botbuilder-dialogs-adaptive
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const baseInvokeDialog_1 = require("./baseInvokeDialog");
const adaptive_expressions_1 = require("adaptive-expressions");
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
/**
* Action which repeats the active [Dialog](xref:botbuilder-dialogs.Dialog) (restarting it).
*/
class RepeatDialog extends baseInvokeDialog_1.BaseInvokeDialog {
/**
* Initializes a new instance of the [RepeatDialog](xref:botbuilder-dialogs-adaptive.RepeatDialog) class.
*
* @param options Optional. Object with additional options.
*/
constructor(options) {
super(undefined, options);
}
/**
* @param property The key of the conditional selector configuration.
* @returns The converter for the selector configuration.
*/
getConverter(property) {
switch (property) {
case 'disabled':
return new adaptive_expressions_1.BoolExpressionConverter();
case 'allowLoop':
return new adaptive_expressions_1.BoolExpressionConverter();
default:
return super.getConverter(property);
}
}
/**
* Starts a new [Dialog](xref:botbuilder-dialogs.Dialog) and pushes it onto the dialog stack.
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation.
* @param options Optional. Initial information to pass to the dialog.
* @returns A `Promise` representing the asynchronous operation.
*/
beginDialog(dc, options) {
return __awaiter(this, void 0, void 0, function* () {
if (this.disabled && this.disabled.getValue(dc.state)) {
return yield dc.endDialog();
}
const boundOptions = this.bindOptions(dc, options);
const targetDialogId = dc.parent.activeDialog.id;
const repeatedIds = dc.state.getValue(botbuilder_dialogs_1.TurnPath.repeatedIds, []);
if (repeatedIds.includes(targetDialogId)) {
if (this.allowLoop == null || this.allowLoop.getValue(dc.state) == false) {
throw new Error(`Recursive loop detected, ${targetDialogId} cannot be repeated twice in one turn.`);
}
}
else {
repeatedIds.push(targetDialogId);
}
dc.state.setValue(botbuilder_dialogs_1.TurnPath.repeatedIds, repeatedIds);
// set the activity processed state (default is true)
dc.state.setValue(botbuilder_dialogs_1.TurnPath.activityProcessed, this.activityProcessed.getValue(dc.state));
const turnResult = yield dc.parent.replaceDialog(dc.parent.activeDialog.id, boundOptions);
turnResult.parentEnded = true;
return turnResult;
});
}
}
exports.RepeatDialog = RepeatDialog;
RepeatDialog.$kind = 'Microsoft.RepeatDialog';
//# sourceMappingURL=repeatDialog.js.map