UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

117 lines 4.91 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.TraceActivity = void 0; /** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ const botbuilder_1 = require("botbuilder"); const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); /** * Send an trace activity back to the transcript. */ class TraceActivity extends botbuilder_dialogs_1.Dialog { /** * Initializes a new instance of the [TraceActivity](xref:botbuilder-dialogs-adaptive.TraceActivity) class. * * @param name Optional. Name of the trace activity. * @param valueType Optional. Value type of the trace activity. * @param value Optional. Value expression to send as the value. * @param label Optional. Label to use when describing a trace activity. */ constructor(name, valueType, value, label) { super(); if (name) { this.name = new adaptive_expressions_1.StringExpression(name); } if (valueType) { this.valueType = new adaptive_expressions_1.StringExpression(valueType); } if (value) { this.value = new adaptive_expressions_1.ValueExpression(value); } if (label) { this.label = new adaptive_expressions_1.StringExpression(label); } } /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'name': return new adaptive_expressions_1.StringExpressionConverter(); case 'valueType': return new adaptive_expressions_1.StringExpressionConverter(); case 'value': return new adaptive_expressions_1.ValueExpressionConverter(); case 'label': return new adaptive_expressions_1.StringExpressionConverter(); case 'disabled': return new adaptive_expressions_1.BoolExpressionConverter(); default: return super.getConverter(property); } } /** * Starts a new [Dialog](xref:botbuilder-dialogs.Dialog) and pushes it 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(); } let value; if (this.value) { value = this.value.getValue(dc.state); } else { value = dc.state.getMemorySnapshot(); } const name = (this.name && this.name.getValue(dc.state)) || 'Trace'; const valueType = (this.valueType && this.valueType.getValue(dc.state)) || 'State'; const label = (this.label && this.label.getValue(dc.state)) || (dc.parent && dc.parent.activeDialog && dc.parent.activeDialog.id) || ''; const traceActivity = { type: botbuilder_1.ActivityTypes.Trace, timestamp: new Date(), name, value, valueType, label, }; yield dc.context.sendActivity(traceActivity); return yield dc.endDialog(traceActivity); }); } /** * @protected * Builds the compute Id for the [Dialog](xref:botbuilder-dialogs.Dialog). * @returns A `string` representing the compute Id. */ onComputeId() { return `TraceActivity[${this.name ? this.name.toString() : ''}]`; } } exports.TraceActivity = TraceActivity; TraceActivity.$kind = 'Microsoft.TraceActivity'; //# sourceMappingURL=traceActivity.js.map