UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

123 lines 5.07 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.LogAction = void 0; /** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ const botbuilder_1 = require("botbuilder"); const templates_1 = require("../templates"); const textTemplateConverter_1 = require("../converters/textTemplateConverter"); const telemetryLoggerConstants_1 = require("../telemetryLoggerConstants"); const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); /** * Write entry into application trace logs. */ class LogAction extends botbuilder_dialogs_1.Dialog { /** * Creates a new [LogAction](xref:botbuilder-dialogs-adaptive.LogAction) instance. * * @param text Optional. The text template to log. */ constructor(text) { super(); /** * If true, the message will both be logged to the console and sent as a trace activity. * Defaults to a value of false. */ this.traceActivity = new adaptive_expressions_1.BoolExpression(false); if (text) { this.text = new templates_1.TextTemplate(text); } } /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'text': return new textTemplateConverter_1.TextTemplateConverter(); case 'traceActivity': return new adaptive_expressions_1.BoolExpressionConverter(); 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(); } if (!this.text) { throw new Error(`${this.id}: no 'message' specified.`); } const msg = yield this.text.bind(dc, dc.state); this.telemetryClient.trackEvent({ name: telemetryLoggerConstants_1.TelemetryLoggerConstants.GeneratorResultEvent, properties: { template: this.text, result: msg || '', context: telemetryLoggerConstants_1.TelemetryLoggerConstants.LogActionResultEvent, }, }); // Log to console and send trace if needed console.log(msg); let label = ''; if (this.label) { label = this.label.getValue(dc.state); } else { if (dc.parent && dc.parent.activeDialog && dc.parent.activeDialog.id) { label = dc.parent.activeDialog.id; } } if (this.traceActivity && this.traceActivity.getValue(dc.state)) { const activity = { type: botbuilder_1.ActivityTypes.Trace, name: 'LogAction', valueType: 'string', value: msg, label: label, }; yield dc.context.sendActivity(activity); } 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 `LogAction[${this.text}]`; } } exports.LogAction = LogAction; LogAction.$kind = 'Microsoft.LogAction'; //# sourceMappingURL=logAction.js.map