UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

77 lines 3.88 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.ContinueConversation = void 0; const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_1 = require("botbuilder"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); /** * Action which continues a conversation using a Conversation reference. */ class ContinueConversation 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 'conversationReference': return new adaptive_expressions_1.ObjectExpressionConverter(); case 'value': return new adaptive_expressions_1.ValueExpressionConverter(); 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, _b; 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 conversationReference = this.conversationReference.getValue(dc.state); const continueActivity = botbuilder_1.TurnContext.applyConversationReference({ type: botbuilder_1.ActivityTypes.Event, name: botbuilder_1.ActivityEventNames.ContinueConversation, relatesTo: conversationReference, value: (_b = this.value) === null || _b === void 0 ? void 0 : _b.getValue(dc.state), }, conversationReference, true); const queueStorage = dc.context.turnState.get(botbuilder_dialogs_1.DialogTurnStateConstants.queueStorage); if (!queueStorage) { throw new Error('Unable to locate QueueStorage in HostContext'); } const receipt = yield queueStorage.queueActivity(continueActivity); // return ths receipt as the result. return dc.endDialog(receipt); }); } /** * Builds the compute id for the dialog. * * @returns {string} A string representing the compute id. */ onComputeId() { var _a, _b; return `ContinueConversation[${(_b = (_a = this.conversationReference) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}]`; } } exports.ContinueConversation = ContinueConversation; ContinueConversation.$kind = 'Microsoft.ContinueConversation'; //# sourceMappingURL=continueConversation.js.map