botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
62 lines • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConditionalSelector = void 0;
const triggerSelector_1 = require("../triggerSelector");
const adaptive_expressions_1 = require("adaptive-expressions");
/**
* Select between two rule selectors based on a condition.
*/
class ConditionalSelector extends triggerSelector_1.TriggerSelector {
constructor() {
super(...arguments);
/**
* Gets or sets the expression parser to use.
*/
this.parser = new adaptive_expressions_1.ExpressionParser();
}
/**
* Gets the converter for the selector configuration.
*
* @param property The key of the conditional selector configuration.
* @returns The converter for the selector configuration.
*/
getConverter(property) {
switch (property) {
case 'condition':
return new adaptive_expressions_1.BoolExpressionConverter();
default:
return super.getConverter(property);
}
}
/**
* 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) {
let selector;
if (this.condition && this.condition.getValue(actionContext.state)) {
selector = this.ifTrue;
this.ifTrue.initialize(this._conditionals, this._evaluate);
}
else {
selector = this.ifFalse;
this.ifFalse.initialize(this._conditionals, this._evaluate);
}
return selector.select(actionContext);
}
}
exports.ConditionalSelector = ConditionalSelector;
ConditionalSelector.$kind = 'Microsoft.ConditionalSelector';
//# sourceMappingURL=conditionalSelector.js.map