UNPKG

botbuilder-dialogs

Version:

A dialog stack based conversation manager for Microsoft BotBuilder.

97 lines 3.99 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.BotStateMemoryScope = void 0; const memoryScope_1 = require("./memoryScope"); /** * Base class for memory scopes based on BotState. */ class BotStateMemoryScope extends memoryScope_1.MemoryScope { /** * Initializes a new instance of the [BotStateMemoryScope](xref:adaptive-expressions.BotStateMemoryScope) class. * * @param name name of the property. */ constructor(name) { super(name, true); } /** * Get the backing memory for this scope. * * @param dc current dialog context. * @returns Memory for the scope. */ getMemory(dc) { const botState = dc.context.turnState.get(this.stateKey); if (botState) { return botState.get(dc.context); } return undefined; } /** * Changes the backing object for the memory scope. * * @param dc current dialog context * @param _memory memory */ setMemory(dc, _memory) { const botState = dc.context.turnState.get(this.stateKey); if (!botState) { throw new Error(`${this.stateKey} is not available.`); } throw new Error('You cannot replace the root BotState object.'); } /** * Populates the state cache for this [BotState](xref:botbuilder-core.BotState) from the storage layer. * * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) object for this turn. * @param force Optional, `true` to overwrite any existing state cache; * or `false` to load state from storage only if the cache doesn't already exist. * @returns A Promise that represents the work queued to execute. */ load(dc, force = false) { return __awaiter(this, void 0, void 0, function* () { const botState = dc.context.turnState.get(this.stateKey); if (botState) { yield botState.load(dc.context, force); } }); } /** * Writes the state cache for this [BotState](xref:botbuilder-core.BotState) to the storage layer. * * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) object for this turn. * @param force Optional, `true` to save the state cache to storage; * or `false` to save state to storage only if a property in the cache has changed. * @returns A Promise that represents the work queued to execute. */ saveChanges(dc, force = false) { return __awaiter(this, void 0, void 0, function* () { const botState = dc.context.turnState.get(this.stateKey); if (botState) { yield botState.saveChanges(dc.context, force); } }); } /** * Deletes any state in storage and the cache for this [BotState](xref:botbuilder-core.BotState). * * @param _dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) object for this turn. * @returns A Promise that represents the work queued to execute. */ delete(_dc) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(); }); } } exports.BotStateMemoryScope = BotStateMemoryScope; //# sourceMappingURL=botStateMemoryScope.js.map