UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

52 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TrueSelector = void 0; /** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ const triggerSelector_1 = require("../triggerSelector"); /** * Select all rules which evaluate to true. */ class TrueSelector extends triggerSelector_1.TriggerSelector { /** * Initialize the selector with the set of rules. * * @param conditionals Possible rules to match. * @param evaluate True if rules should be evaluated on select. */ initialize(conditionals, evaluate) { this._conditionals = conditionals; this._evaluate = evaluate; } /** * Select the best rule to execute. * * @param actionContext Dialog context for evaluation. * @returns A Promise with a number array. */ select(actionContext) { const candidates = []; for (let i = 0; i < this._conditionals.length; i++) { const conditional = this._conditionals[i]; if (this._evaluate) { const expression = conditional.getExpression(); const { value, error } = expression.tryEvaluate(actionContext.state); if (value && !error) { candidates.push(conditional); } } else { candidates.push(conditional); } } return Promise.resolve(candidates); } } exports.TrueSelector = TrueSelector; TrueSelector.$kind = 'Microsoft.TrueSelector'; //# sourceMappingURL=trueSelector.js.map