UNPKG

@microsoft/omnichannel-chat-sdk

Version:
88 lines 4.79 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var EventMarker_1 = require("./EventMarker"); var ScenarioType_1 = require("./ScenarioType"); var StopWatch_1 = require("./StopWatch"); var ScenarioMarker = /** @class */ (function () { function ScenarioMarker(omnichannelConfig) { this.omnichannelConfig = omnichannelConfig; this.runtimeId = ''; this.telemetry = null; this.debug = false; this.telemetryEvents = new Map(); this.scenarioType = ScenarioType_1.default.EVENTS; } /* istanbul ignore next */ ScenarioMarker.prototype.setDebug = function (flag) { var _a; this.debug = flag; (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setDebug(flag); }; ScenarioMarker.prototype.setScenarioType = function (scenarioType) { this.scenarioType = scenarioType; }; ScenarioMarker.prototype.setRuntimeId = function (runtimeId) { this.runtimeId = runtimeId; }; ScenarioMarker.prototype.useTelemetry = function (telemetry) { this.debug && console.log("[ScenarioMarker][useTelemetry]"); this.telemetry = telemetry; }; ScenarioMarker.prototype.startScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } this.debug && console.log("[ScenarioMarker][startScenario]"); if (!this.telemetryEvents.has(event)) { var stopWatch = new StopWatch_1.default(); stopWatch.start(); this.telemetryEvents.set(event, stopWatch); } var properties = __assign({ ChatSDKRuntimeId: this.runtimeId, Event: (0, EventMarker_1.startEvent)(event), OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId }, additionalProperties); (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.info(properties, this.scenarioType); }; ScenarioMarker.prototype.singleRecord = function (event, additionalProperties) { var _a; var properties = __assign({ ChatSDKRuntimeId: this.runtimeId, Event: event, OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId }, additionalProperties); (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.info(properties, this.scenarioType); }; ScenarioMarker.prototype.failScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } this.debug && console.log("[ScenarioMarker][failScenario]"); if (!this.telemetryEvents.has(event)) { console.warn("'".concat(event, "' event has not started.")); return; } var stopWatch = this.telemetryEvents.get(event); this.telemetryEvents.delete(event); var properties = __assign({ ChatSDKRuntimeId: this.runtimeId, Event: (0, EventMarker_1.failEvent)(event), OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId, ElapsedTimeInMilliseconds: stopWatch.stop() }, additionalProperties); (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.error(properties, this.scenarioType); }; ScenarioMarker.prototype.completeScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } this.debug && console.log("[ScenarioMarker][completeScenario]"); if (!this.telemetryEvents.has(event)) { console.warn("'".concat(event, "' event has not started.")); return; } var stopWatch = this.telemetryEvents.get(event); this.telemetryEvents.delete(event); var properties = __assign({ ChatSDKRuntimeId: this.runtimeId, Event: (0, EventMarker_1.completeEvent)(event), OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId, ElapsedTimeInMilliseconds: stopWatch.stop() }, additionalProperties); (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.info(properties, this.scenarioType); }; return ScenarioMarker; }()); exports.default = ScenarioMarker; //# sourceMappingURL=ScenarioMarker.js.map