UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

106 lines 4.93 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.TelemetryTrackEventAction = void 0; const adaptive_expressions_1 = require("adaptive-expressions"); const botbuilder_dialogs_1 = require("botbuilder-dialogs"); /** * Converter to convert telemetry properties configuration. */ class TelemetryPropertiesConverter { /** * Converts a [PropertiesInput](xref:botbuilder-dialogs-adaptive.PropertiesInput) or [PropertiesOutput](xref:botbuilder-dialogs-adaptive.PropertiesOutput) into telemetry [PropertiesOutput](xref:botbuilder-dialogs-adaptive.PropertiesOutput). * * @param value The [PropertiesInput](xref:botbuilder-dialogs-adaptive.PropertiesInput) or [PropertiesOutput](xref:botbuilder-dialogs-adaptive.PropertiesOutput) to convert. * @returns The converted [StringExpression](xref:adaptive-expressions.StringExpression). */ convert(value) { return Object.entries(value).reduce((properties, [key, value]) => { const property = value instanceof adaptive_expressions_1.StringExpression ? value : new adaptive_expressions_1.StringExpression(value); return Object.assign(Object.assign({}, properties), { [key]: property }); }, {}); } } /** * Track a custom event. */ class TelemetryTrackEventAction extends botbuilder_dialogs_1.Dialog { /** * Initializes a new instance of the [TelemetryTrackEventAction](xref:botbuilder-dialogs-adaptive.TelemetryTrackEventAction) class. * * @param eventName Optional. Name to use for the event. * @param properties Optional. Properties to attach to the tracked event. */ constructor(eventName, properties) { super(); if (eventName) { this.eventName = new adaptive_expressions_1.StringExpression(eventName); } if (properties) { this.properties = {}; for (const name in properties) { this.properties[name] = new adaptive_expressions_1.StringExpression(properties[name]); } } } /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property) { switch (property) { case 'eventName': return new adaptive_expressions_1.StringExpressionConverter(); case 'properties': return new TelemetryPropertiesConverter(); 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.eventName) { const name = this.eventName.getValue(dc.state); const properties = {}; if (this.properties) { for (const name in this.properties) { properties[name] = this.properties[name].getValue(dc.state); } } this.telemetryClient.trackEvent({ name, properties }); } 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 `TelemetryTrackEventAction[${this.eventName && this.eventName.toString()}]`; } } exports.TelemetryTrackEventAction = TelemetryTrackEventAction; TelemetryTrackEventAction.$kind = 'Microsoft.TelemetryTrackEventAction'; //# sourceMappingURL=telemetryTrackEventAction.js.map