UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

66 lines 3.16 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.GetConversationReference = void 0; const botbuilder_1 = require("botbuilder"); const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); /** * Gets the current conversation reference and saves it to a memory property suitable to use in ContinueConversation action. */ class GetConversationReference extends botbuilder_dialogs_1.Dialog { /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'disabled': return new adaptive_expressions_1.BoolExpressionConverter(); case 'property': return new adaptive_expressions_1.StringExpressionConverter(); default: return super.getConverter(property); } } /** * Called when the dialog is started and pushed onto the dialog stack. * * @param {DialogContext} dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @param {Record<string, ?>} _options Optional, initial information to pass to the dialog. * @returns {Promise<DialogTurnResult>} A promise representing the asynchronous operation. */ beginDialog(dc, _options) { var _a; return __awaiter(this, void 0, void 0, function* () { if ((_a = this.disabled) === null || _a === void 0 ? void 0 : _a.getValue(dc.state)) { return dc.endDialog(); } const cr = botbuilder_1.TurnContext.getConversationReference(dc.context.activity); if (this.property) { dc.state.setValue(this.property.getValue(dc.stack), cr); } return dc.endDialog(cr); }); } /** * Builds the compute id for the dialog. * * @returns {string} A string representing the compute id. */ onComputeId() { var _a, _b; return `GetConversationReference[${(_b = (_a = this.property) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}]`; } } exports.GetConversationReference = GetConversationReference; GetConversationReference.$kind = 'Microsoft.GetConversationReference'; //# sourceMappingURL=getConversationReference.js.map