UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

95 lines 4.05 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.EndDialog = void 0; const jsonExtensions_1 = require("../jsonExtensions"); const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); /** * Command to end the current [Dialog](xref:botbuilder-dialogs.Dialog), returning the `resultProperty` as the result of the dialog. */ class EndDialog extends botbuilder_dialogs_1.Dialog { /** * Creates a new `EndDialog` instance. * * @param value Optional, a value expression for the result to be returned to the caller. */ constructor(value) { super(); if (value) { this.value = new adaptive_expressions_1.ValueExpression(value); } } /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'value': return new adaptive_expressions_1.ValueExpressionConverter(); 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) { return __awaiter(this, void 0, void 0, function* () { if (this.disabled && this.disabled.getValue(dc.state)) { return yield dc.endDialog(); } if (this.value) { const value = (0, jsonExtensions_1.evaluateExpression)(dc.state, this.value); return yield this.endParentDialog(dc, value); } return yield this.endParentDialog(dc); }); } /** * Ends the parent [Dialog](xref:botbuilder-dialogs.Dialog). * * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @param result Optional. Value returned from the dialog that was called. The type * of the value returned is dependent on the child dialog. * @returns A `Promise` representing the asynchronous operation. */ endParentDialog(dc, result) { return __awaiter(this, void 0, void 0, function* () { if (dc.parent) { const turnResult = yield dc.parent.endDialog(result); turnResult.parentEnded = true; return turnResult; } else { return yield dc.endDialog(result); } }); } /** * @protected * Builds the compute Id for the [Dialog](xref:botbuilder-dialogs.Dialog). * @returns A `string` representing the compute Id. */ onComputeId() { return `EndDialog[${this.value ? this.value.toString() : ''}]`; } } exports.EndDialog = EndDialog; EndDialog.$kind = 'Microsoft.EndDialog'; //# sourceMappingURL=endDialog.js.map