UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

109 lines 4.79 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.EmitEvent = void 0; const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); /** * Action which emits an event declaratively. */ class EmitEvent extends botbuilder_dialogs_1.Dialog { /** * Initializes a new instance of the [EmitEvent](xref:botbuilder-dialogs-adaptive.EmitEvent) class. * * @param eventName Optional. Name of the event to emit. * @param eventValue Optional. Memory property path to use to get the value to send as part of the event. * @param bubbleEvent Default = `false`. Value indicating whether the event should bubble to parents or not. */ constructor(eventName, eventValue, bubbleEvent = false) { super(); /** * The property path to store whether the event was handled or not. */ this.handledProperty = new adaptive_expressions_1.StringExpression('turn.eventHandled'); if (eventName) { this.eventName = new adaptive_expressions_1.StringExpression(eventName); } if (eventValue) { this.eventValue = new adaptive_expressions_1.ValueExpression(eventValue); } this.bubbleEvent = new adaptive_expressions_1.BoolExpression(bubbleEvent); } /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'eventName': case 'handledProperty': return new adaptive_expressions_1.StringExpressionConverter(); case 'eventValue': return new adaptive_expressions_1.ValueExpressionConverter(); case 'bubbleEvent': case 'disabled': 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) { var _a; return __awaiter(this, void 0, void 0, function* () { if (this.disabled && this.disabled.getValue(dc.state)) { return yield dc.endDialog(); } let eventName; if (this.eventName) { eventName = this.eventName.getValue(dc.state); } let eventValue; if (this.eventValue) { eventValue = this.eventValue.getValue(dc.state); } let bubbleEvent = false; if (this.bubbleEvent) { bubbleEvent = this.bubbleEvent.getValue(dc.state); } let handled = false; if (dc.parent) { handled = yield dc.parent.emitEvent(eventName, eventValue, bubbleEvent, false); } else { handled = yield dc.emitEvent(eventName, eventValue, bubbleEvent, false); } // Save results of operation. const handledProperty = (_a = this.handledProperty) === null || _a === void 0 ? void 0 : _a.getValue(dc.state); if (handledProperty) { dc.state.setValue(handledProperty, handled); } return yield dc.endDialog(handled); }); } /** * @protected * Builds the compute Id for the [Dialog](xref:botbuilder-dialogs.Dialog). * @returns A `string` representing the compute Id. */ onComputeId() { return `EmitEvent[${this.eventName.toString() || ''}]`; } } exports.EmitEvent = EmitEvent; EmitEvent.$kind = 'Microsoft.EmitEvent'; //# sourceMappingURL=emitEvent.js.map