UNPKG

botbuilder-core

Version:

Core components for Microsoft Bot Builder. Components in this library can run either in a browser or on the server.

79 lines 4.08 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. 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.SkillConversationIdFactory = void 0; const skillConversationIdFactoryBase_1 = require("./skillConversationIdFactoryBase"); const turnContext_1 = require("../turnContext"); const uuid_1 = require("uuid"); /** * A SkillConversationIdFactory that stores and retrieves [ConversationReference](xref:botframework-schema:ConversationReference) instances. */ class SkillConversationIdFactory extends skillConversationIdFactoryBase_1.SkillConversationIdFactoryBase { /** * Creates a new instance of the SkillConversationIdFactory class. * * @param storage The storage for the [ConversationReference](xref:botframework-schema:ConversationReference) instances. */ constructor(storage) { super(); this.storage = storage; } /** * Creates a conversation ID for a skill conversation based on the caller's [ConversationReference](xref:botframework-schema:ConversationReference). * * @param options The [SkillConversationIdFactoryOptions](xref:botbuilder-core.SkillConversationIdFactoryOptions) to use. * @returns {Promise<string>} A unique conversation ID used to communicate with the skill. */ createSkillConversationIdWithOptions(options) { return __awaiter(this, void 0, void 0, function* () { const conversationReference = turnContext_1.TurnContext.getConversationReference(options.activity); const skillConversationId = (0, uuid_1.v4)(); const skillConversationReference = { conversationReference: conversationReference, oAuthScope: options.fromBotOAuthScope, }; yield this.storage.write({ [skillConversationId]: skillConversationReference }); return skillConversationId; }); } /** * Gets the ConversationReference created using createSkillConversationId() for a skillConversationId. * * @param skillConversationId A skill conversationId created using createSkillConversationId(). * @returns {Promise<SkillConversationReference>} The caller's ConversationReference for a skillConversationId. Null if not found. */ getSkillConversationReference(skillConversationId) { return __awaiter(this, void 0, void 0, function* () { const skillConversationInfo = yield this.storage.read([skillConversationId]); if (!skillConversationInfo) { return undefined; } const skillConversationReference = skillConversationInfo[skillConversationId]; if (!skillConversationReference) { return undefined; } return skillConversationReference; }); } /** * Deletes the [SkillConversationReference](xref:botbuilder-core.SkillConversationReference) from the storage. * * @param skillConversationId The skill conversation id to use as key for the delete. * @returns {Promise<void>} A promise representing the asynchronous operation. */ deleteConversationReference(skillConversationId) { return this.storage.delete([skillConversationId]); } } exports.SkillConversationIdFactory = SkillConversationIdFactory; //# sourceMappingURL=skillConversationIdFactory.js.map