UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

91 lines 3.74 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.DeleteProperties = void 0; /** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); class PropertiesConverter { convert(items) { return items.map((item) => (typeof item === 'string' ? new adaptive_expressions_1.StringExpression(item) : item)); } } /** * Deletes a collection of properties from memory. */ class DeleteProperties extends botbuilder_dialogs_1.Dialog { /** * Initializes a new instance of the [DeleteProperties](xref:botbuilder-dialogs-adaptive.DeleteProperties) class. * * @param properties Optional. Collection of property paths to remove. */ constructor(properties) { super(); /** * Collection of property paths to remove. */ this.properties = []; if (properties) { this.properties = properties.map((property) => new adaptive_expressions_1.StringExpression(property)); } } /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'properties': return new PropertiesConverter(); case 'disabled': return new adaptive_expressions_1.BoolExpressionConverter(); default: return super.getConverter(property); } } /** * Called when the [Dialog](xref:botbuilder-dialogs.Dialog) is started and pushed 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.properties && this.properties.length > 0) { for (let i = 0; i < this.properties.length; i++) { dc.state.deleteValue(this.properties[i].getValue(dc.state)); } } return yield dc.endDialog(); }); } /** * @protected * Builds the compute Id for the [Dialog](xref:botbuilder-dialogs.Dialog). * @returns A `string` representing the compute Id. */ onComputeId() { return `DeleteProperties[${this.properties.map((property) => property.toString()).join(',')}]`; } } exports.DeleteProperties = DeleteProperties; DeleteProperties.$kind = 'Microsoft.DeleteProperties'; //# sourceMappingURL=deleteProperties.js.map