UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

95 lines 4.62 kB
"use strict"; 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.CancelAllDialogsBase = void 0; const botbuilder_dialogs_1 = require("botbuilder-dialogs"); const adaptive_expressions_1 = require("adaptive-expressions"); /** * Base class for [CancelAllDialogs](xref:botbuilder-dialogs-adaptive.CancelAllDialogs) api. */ class CancelAllDialogsBase extends botbuilder_dialogs_1.Dialog { /** * Initializes a new instance of the [CancelAllDialogsBase](xref:botbuilder-dialogs-adaptive.CancelAllDialogsBase) class. * * @param eventName Optional. Expression for event name. * @param eventValue Optional. Expression for event value. * @param isCancelAll Set to `true` to cancel all [Dialogs](xref:botbuilder-dialogs.Dialog); `false` otherwise. */ constructor(eventName, eventValue, isCancelAll = true) { super(); if (eventName) { this.eventName = new adaptive_expressions_1.StringExpression(eventName); } if (eventValue) { this.eventValue = new adaptive_expressions_1.ValueExpression(eventValue); } this._cancelAll = isCancelAll; } /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'eventName': return new adaptive_expressions_1.StringExpressionConverter(); case 'eventValue': return new adaptive_expressions_1.ValueExpressionConverter(); case 'disabled': return new adaptive_expressions_1.BoolExpressionConverter(); case 'activityProcessed': return new adaptive_expressions_1.BoolExpressionConverter(); default: return super.getConverter(property); } } /** * Called when the [Dialog](xref:botbuilder-dialogs.Dialog) is started and pushed 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(); } let eventName = this.eventName && this.eventName.getValue(dc.state); let eventValue = this.eventValue && this.eventValue.getValue(dc.state); if (this.activityProcessed && this.activityProcessed.getValue(dc.state) == false) { // mark that this hasn't been recognized dc.state.setValue(botbuilder_dialogs_1.TurnPath.activityProcessed, false); // emit ActivityReceived, which will tell parent it's supposed to handle recognition. eventName = botbuilder_dialogs_1.DialogEvents.activityReceived; eventValue = dc.context.activity; } if (!dc.parent) { return yield dc.cancelAllDialogs(this._cancelAll, eventName, eventValue); } else { const turnResult = yield dc.parent.cancelAllDialogs(this._cancelAll, eventName, eventValue); turnResult.parentEnded = true; return turnResult; } }); } /** * @protected * Builds the compute Id for the [Dialog](xref:botbuilder-dialogs.Dialog). * @returns A `string` representing the compute Id. */ onComputeId() { return `${this.constructor.name}[${this.eventName ? this.eventName.toString() : ''}]`; } } exports.CancelAllDialogsBase = CancelAllDialogsBase; //# sourceMappingURL=cancelAllDialogsBase.js.map