botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
58 lines • 2.04 kB
JavaScript
;
/**
* @module botbuilder-dialogs-adaptive
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.IsDialogActiveFunction = void 0;
const adaptive_expressions_1 = require("adaptive-expressions");
/**
* Defines isDialogActive(id) expression function.
* This expression will return true if any of the dialog ids is on the dialog execution stack.
*
* @example isDialogActive('dialog1')
* @example isDialogActive('dialog1', 'dialog2', 'dialog3')
*/
class IsDialogActiveFunction extends adaptive_expressions_1.ExpressionEvaluator {
/**
* Intializes a new instance of the [IsDialogActiveFunction](xref:botbuilder-dialogs-adaptive.IsDialogActiveFunction) class.
*/
constructor() {
super(IsDialogActiveFunction.functionName, IsDialogActiveFunction.function, adaptive_expressions_1.ReturnType.Boolean);
}
static function(expression, state, options) {
const stack = state.getValue('dialogcontext.stack');
if (!stack) {
return { value: undefined, error: 'dialogcontext.stack not found' };
}
try {
const args = expression.children.map((child) => {
const { value, error } = child.tryEvaluate(state, options);
if (error) {
throw error;
}
return value;
});
return {
value: stack.some((dlg) => args.includes(dlg)),
error: undefined,
};
}
catch (error) {
return { value: undefined, error };
}
}
}
exports.IsDialogActiveFunction = IsDialogActiveFunction;
/**
* Function identifier name.
*/
IsDialogActiveFunction.functionName = 'isDialogActive'; // `name` is reserved in JavaScript.
/**
* Function identifier alias.
*/
IsDialogActiveFunction.functionAlias = 'isActionActive';
//# sourceMappingURL=isDialogActiveFunction.js.map