UNPKG

@microsoft/omnichannel-chat-sdk

Version:
722 lines 40.6 kB
"use strict"; /* eslint-disable @typescript-eslint/no-non-null-assertion */ 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var ocsdk_1 = require("@microsoft/ocsdk"); var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core"); var ChatAdapterProtocols_1 = require("./core/ChatAdapterProtocols"); var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode"); var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType"); var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType"); var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType"); var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType"); var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType"); var platform_1 = require("./utils/platform"); var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType"); var libraries_1 = require("./utils/libraries"); var utilities_1 = require("./utils/utilities"); var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator"); var SDKConfigValidators_1 = require("./validators/SDKConfigValidators"); var WebUtils_1 = require("./utils/WebUtils"); var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling"); var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber"); var OmnichannelChatSDK = /** @class */ (function () { function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) { if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; } this.authSettings = null; this.authenticatedUserToken = null; this.conversation = null; this.callingOption = CallingOptionsOptionSetNumber_1.default.NoCalling; this.debug = false; this.omnichannelConfig = omnichannelConfig; this.chatSDKConfig = chatSDKConfig; this.requestId = ocsdk_1.uuidv4(); this.chatToken = {}; this.liveChatConfig = {}; this.dataMaskingRules = {}; this.authSettings = null; this.preChatSurvey = null; OmnichannelConfigValidator_1.default(omnichannelConfig); SDKConfigValidators_1.default(chatSDKConfig); } /* istanbul ignore next */ OmnichannelChatSDK.prototype.setDebug = function (flag) { this.debug = flag; }; OmnichannelChatSDK.prototype.initialize = function () { return __awaiter(this, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: this.OCSDKProvider = ocsdk_1.SDKProvider; _a = this; return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, {}, undefined)]; case 1: _a.OCClient = _c.sent(); // eslint-disable-line @typescript-eslint/no-explicit-any _b = this; return [4 /*yield*/, this.getIC3Client()]; case 2: _b.IC3Client = _c.sent(); return [2 /*return*/, this.getChatConfig()]; } }); }); }; OmnichannelChatSDK.prototype.startChat = function (optionalParams) { if (optionalParams === void 0) { optionalParams = {}; } return __awaiter(this, void 0, void 0, function () { var sessionInitOptionalParams, error_1, error_2, _a, error_3; return __generator(this, function (_b) { switch (_b.label) { case 0: if (optionalParams.liveChatContext) { this.chatToken = optionalParams.liveChatContext.chatToken || {}; this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4(); } if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 2]; return [4 /*yield*/, this.getChatToken(false)]; case 1: _b.sent(); _b.label = 2; case 2: sessionInitOptionalParams = { initContext: {} }; if (optionalParams.preChatResponse) { sessionInitOptionalParams.initContext.preChatResponse = optionalParams.preChatResponse; } if (this.authenticatedUserToken) { sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken; } _b.label = 3; case 3: _b.trys.push([3, 5, , 6]); return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)]; case 4: _b.sent(); return [3 /*break*/, 6]; case 5: error_1 = _b.sent(); console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_1); return [2 /*return*/, error_1]; case 6: _b.trys.push([6, 8, , 9]); return [4 /*yield*/, this.IC3Client.initialize({ token: this.chatToken.token, regionGtms: this.chatToken.regionGTMS, visitor: true })]; case 7: _b.sent(); return [3 /*break*/, 9]; case 8: error_2 = _b.sent(); console.error("OmnichannelChatSDK/startChat/initialize/error " + error_2); return [2 /*return*/, error_2]; case 9: _b.trys.push([9, 11, , 12]); _a = this; return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)]; case 10: _a.conversation = _b.sent(); return [3 /*break*/, 12]; case 11: error_3 = _b.sent(); console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_3); return [2 /*return*/, error_3]; case 12: return [2 /*return*/]; } }); }); }; OmnichannelChatSDK.prototype.endChat = function () { return __awaiter(this, void 0, void 0, function () { var sessionCloseOptionalParams, error_4; return __generator(this, function (_a) { switch (_a.label) { case 0: sessionCloseOptionalParams = {}; if (this.authenticatedUserToken) { sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken; } _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)]; case 2: _a.sent(); this.conversation.disconnect(); this.conversation = null; this.requestId = ocsdk_1.uuidv4(); this.chatToken = {}; return [3 /*break*/, 4]; case 3: error_4 = _a.sent(); console.error("OmnichannelChatSDK/endChat/error " + error_4); return [2 /*return*/, error_4]; case 4: return [2 /*return*/]; } }); }); }; OmnichannelChatSDK.prototype.getCurrentLiveChatContext = function () { return __awaiter(this, void 0, void 0, function () { var chatToken, requestId, chatSession; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getChatToken()]; case 1: chatToken = _a.sent(); requestId = this.requestId; chatSession = { chatToken: chatToken, requestId: requestId }; if (Object.keys(chatSession.chatToken).length === 0) { return [2 /*return*/, {}]; } return [2 /*return*/, chatSession]; } }); }); }; /** * Gets PreChat Survey. * @param parse Whether to parse PreChatSurvey to JSON or not. */ OmnichannelChatSDK.prototype.getPreChatSurvey = function (parse) { if (parse === void 0) { parse = true; } return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, parse ? JSON.parse(this.preChatSurvey) : this.preChatSurvey]; }); }); }; OmnichannelChatSDK.prototype.getLiveChatConfig = function (cached) { if (cached === void 0) { cached = true; } return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { if (cached) { return [2 /*return*/, this.liveChatConfig]; } return [2 /*return*/, this.getChatConfig()]; }); }); }; OmnichannelChatSDK.prototype.getChatToken = function (cached) { if (cached === void 0) { cached = true; } return __awaiter(this, void 0, void 0, function () { var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, error_5; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!!cached) return [3 /*break*/, 4]; _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); getChatTokenOptionalParams = {}; if (this.authenticatedUserToken) { getChatTokenOptionalParams.authenticatedUserToken = this.authenticatedUserToken; } return [4 /*yield*/, this.OCClient.getChatToken(this.requestId, getChatTokenOptionalParams)]; case 2: chatToken = _a.sent(); chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken; this.chatToken = { chatId: chatId, regionGTMS: JSON.parse(regionGtms), requestId: this.requestId, token: token, expiresIn: expiresIn, visitorId: visitorId, voiceVideoCallToken: voiceVideoCallToken }; return [3 /*break*/, 4]; case 3: error_5 = _a.sent(); console.error("OmnichannelChatSDK/getChatToken/error " + error_5); return [3 /*break*/, 4]; case 4: return [2 /*return*/, this.chatToken]; } }); }); }; OmnichannelChatSDK.prototype.getMessages = function () { var _a; return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_b) { return [2 /*return*/, (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.getMessages()]; }); }); }; OmnichannelChatSDK.prototype.getDataMaskingRules = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.dataMaskingRules]; }); }); }; OmnichannelChatSDK.prototype.sendMessage = function (message) { return __awaiter(this, void 0, void 0, function () { var _a, disable, maskingCharacter, content, _i, _b, maskingRule, regex, match, replaceStr, messageToSend; return __generator(this, function (_c) { _a = this.chatSDKConfig.dataMasking, disable = _a.disable, maskingCharacter = _a.maskingCharacter; content = message.content; if (Object.keys(this.dataMaskingRules).length > 0 && !disable) { for (_i = 0, _b = Object.values(this.dataMaskingRules); _i < _b.length; _i++) { maskingRule = _b[_i]; regex = new RegExp(maskingRule, 'g'); match = void 0; while (match = regex.exec(content)) { // eslint-disable-line no-cond-assign replaceStr = match[0].replace(/./g, maskingCharacter); content = content.replace(match[0], replaceStr); } } } message.content = content; messageToSend = { content: message.content, timestamp: new Date(), contentType: MessageContentType_1.default.Text, deliveryMode: DeliveryMode_1.default.Bridged, messageType: MessageType_1.default.UserMessage, properties: undefined, tags: [], sender: { displayName: "Customer", id: "customer", type: PersonType_1.default.User } }; if (message.tags) { messageToSend.tags = message.tags; } if (message.timestamp) { messageToSend.timestamp = message.timestamp; } return [2 /*return*/, this.conversation.sendMessage(messageToSend)]; }); }); }; OmnichannelChatSDK.prototype.onNewMessage = function (onNewMessageCallback) { var _a; (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) { var messageType = message.messageType; // Filter out customer messages if (utilities_1.isCustomerMessage(message)) { return; } if (messageType !== MessageType_1.default.Typing) { onNewMessageCallback(message); } }); }; OmnichannelChatSDK.prototype.sendTypingEvent = function () { return __awaiter(this, void 0, void 0, function () { var typingPayload, members, botMembers, error_6; return __generator(this, function (_a) { switch (_a.label) { case 0: typingPayload = "{isTyping: 0}"; _a.label = 1; case 1: _a.trys.push([1, 5, , 6]); return [4 /*yield*/, this.conversation.indicateTypingStatus(0)]; case 2: _a.sent(); return [4 /*yield*/, this.conversation.getMembers()]; case 3: members = _a.sent(); botMembers = members.filter(function (member) { return member.type === PersonType_1.default.Bot; }); return [4 /*yield*/, this.conversation.sendMessageToBot(botMembers[0].id, { payload: typingPayload })]; case 4: _a.sent(); return [3 /*break*/, 6]; case 5: error_6 = _a.sent(); console.error("OmnichannelChatSDK/sendTypingEvent/error"); return [2 /*return*/, error_6]; case 6: return [2 /*return*/]; } }); }); }; OmnichannelChatSDK.prototype.onTypingEvent = function (onTypingEventCallback) { var _a; return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_b) { (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) { var messageType = message.messageType; // Filter out customer messages if (utilities_1.isCustomerMessage(message)) { return; } if (messageType === MessageType_1.default.Typing) { onTypingEventCallback(message); } }); return [2 /*return*/]; }); }); }; OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) { var _a; return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_b) { (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) { var members = message.members; // Agent ending conversation would have 1 member left in the chat thread if (members.length === 1) { onAgentEndSessionCallback(message); } }); return [2 /*return*/]; }); }); }; OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) { return __awaiter(this, void 0, void 0, function () { var fileMetadata, messageToSend, error_7; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.conversation.sendFileData(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)]; case 1: fileMetadata = _a.sent(); messageToSend = { content: "", timestamp: new Date(), contentType: MessageContentType_1.default.Text, deliveryMode: DeliveryMode_1.default.Bridged, messageType: MessageType_1.default.UserMessage, tags: [], sender: { displayName: "Customer", id: "customer", type: PersonType_1.default.User, }, fileMetadata: fileMetadata }; _a.label = 2; case 2: _a.trys.push([2, 4, , 5]); return [4 /*yield*/, this.conversation.sendFileMessage(fileMetadata, messageToSend)]; case 3: _a.sent(); return [2 /*return*/, messageToSend]; case 4: error_7 = _a.sent(); console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_7); return [2 /*return*/, error_7]; case 5: return [2 /*return*/]; } }); }); }; OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.conversation.downloadFile(fileMetadata)]; }); }); }; OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body) { return __awaiter(this, void 0, void 0, function () { var emailTranscriptOptionalParams, emailRequestBody; return __generator(this, function (_a) { emailTranscriptOptionalParams = {}; if (this.authenticatedUserToken) { emailTranscriptOptionalParams.authenticatedUserToken = this.authenticatedUserToken; } emailRequestBody = { ChatId: this.chatToken.chatId, EmailAddress: body.emailAddress, DefaultAttachmentMessage: body.attachmentMessage, CustomerLocale: body.locale }; return [2 /*return*/, this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams)]; }); }); }; OmnichannelChatSDK.prototype.getLiveChatTranscript = function () { return __awaiter(this, void 0, void 0, function () { var getChatTranscriptOptionalParams; return __generator(this, function (_a) { getChatTranscriptOptionalParams = {}; if (this.authenticatedUserToken) { getChatTranscriptOptionalParams.authenticatedUserToken = this.authenticatedUserToken; } return [2 /*return*/, this.OCClient.getChatTranscripts(this.requestId, this.chatToken.chatId, this.chatToken.token, getChatTranscriptOptionalParams)]; }); }); }; OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) { if (protocol === void 0) { protocol = ChatAdapterProtocols_1.default.IC3; } return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { if (platform_1.default.isNode() || platform_1.default.isReactNative()) { return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')]; } if (protocol !== ChatAdapterProtocols_1.default.IC3) { return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")]; } return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { var ic3AdapterCDNUrl; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: ic3AdapterCDNUrl = libraries_1.default.getIC3AdapterCDNUrl(); return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () { /* istanbul ignore next */ _this.debug && console.debug('IC3Adapter loaded!'); var adapterConfig = { chatToken: _this.chatToken, userDisplayName: 'Customer', userId: 'teamsvisitor', sdkURL: libraries_1.default.getIC3ClientCDNUrl() }; var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig); resolve(adapter); }, function () { reject('Failed to load IC3Adapter'); })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); })]; }); }); }; OmnichannelChatSDK.prototype.getVoiceVideoCalling = function (params) { if (params === void 0) { params = {}; } return __awaiter(this, void 0, void 0, function () { var chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: if (platform_1.default.isNode() || platform_1.default.isReactNative()) { return [2 /*return*/, Promise.reject('VoiceVideoCalling is only supported on browser')]; } if (this.callingOption.toString() === CallingOptionsOptionSetNumber_1.default.NoCalling.toString()) { return [2 /*return*/, Promise.reject('Voice and video call is not enabled')]; } return [4 /*yield*/, this.getChatConfig()]; case 1: chatConfig = _a.sent(); liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin; msdyn_widgetsnippet = liveWSAndLiveChatEngJoin.msdyn_widgetsnippet; widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\""); result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex); if (result && result.length) { return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { var spoolSDKCDNUrl, LiveChatWidgetLibCDNUrl; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: spoolSDKCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/spool-sdk/sdk.bundle.js"; return [4 /*yield*/, WebUtils_1.loadScript(spoolSDKCDNUrl, function () { /* istanbul ignore next */ _this.debug && console.debug(spoolSDKCDNUrl + " loaded!"); }, function () { reject('Failed to load SpoolSDK'); })]; case 1: _a.sent(); LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/LiveChatWidgetLibs.min.js"; return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () { var VoiceVideoCalling; return __generator(this, function (_a) { switch (_a.label) { case 0: this.debug && console.debug(LiveChatWidgetLibCDNUrl + " loaded!"); return [4 /*yield*/, createVoiceVideoCalling_1.default(params)]; case 1: VoiceVideoCalling = _a.sent(); resolve(VoiceVideoCalling); return [2 /*return*/]; } }); }); }, function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { reject('Failed to load VoiceVideoCalling'); return [2 /*return*/]; }); }); })]; case 2: _a.sent(); return [2 /*return*/]; } }); }); })]; } return [2 /*return*/]; } }); }); }; OmnichannelChatSDK.prototype.getIC3Client = function () { return __awaiter(this, void 0, void 0, function () { var IC3Client; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!(platform_1.default.isNode() || platform_1.default.isReactNative())) return [3 /*break*/, 2]; this.debug && console.debug('IC3Core'); // Use FramelessBridge from IC3Core this.IC3SDKProvider = omnichannel_ic3core_1.SDKProvider; return [4 /*yield*/, omnichannel_ic3core_1.SDKProvider.getSDK({ hostType: HostType_1.default.Page, protocolType: ProtocoleType_1.default.IC3V1SDK })]; case 1: IC3Client = _a.sent(); IC3Client.setDebug(this.debug); return [2 /*return*/, IC3Client]; case 2: this.debug && console.debug('IC3Client'); // Use IC3Client if browser is detected return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { var ic3ClientCDNUrl; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: ic3ClientCDNUrl = libraries_1.default.getIC3ClientCDNUrl(); window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () { var ic3sdk, IC3SDKProvider, IC3Client; return __generator(this, function (_a) { switch (_a.label) { case 0: // Use FramedBridge from IC3Client /* istanbul ignore next */ this.debug && console.debug('ic3:sdk:load'); ic3sdk = window.Microsoft.CRM.Omnichannel.IC3Client.SDK; IC3SDKProvider = ic3sdk.SDKProvider; this.IC3SDKProvider = IC3SDKProvider; return [4 /*yield*/, IC3SDKProvider.getSDK({ hostType: HostType_1.default.IFrame, protocolType: ProtocoleType_1.default.IC3V1SDK })]; case 1: IC3Client = _a.sent(); resolve(IC3Client); return [2 /*return*/]; } }); }); }); return [4 /*yield*/, WebUtils_1.loadScript(ic3ClientCDNUrl, function () { _this.debug && console.debug('IC3Client loaded!'); }, function () { reject('Failed to load IC3Adapter'); })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); })]; } }); }); }; OmnichannelChatSDK.prototype.getChatConfig = function () { return __awaiter(this, void 0, void 0, function () { var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, isPreChatEnabled, token, error_8; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 5, , 6]); return [4 /*yield*/, this.OCClient.getChatConfig()]; case 1: liveChatConfig = _a.sent(); dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin; setting = dataMaskingConfig.setting; if (setting.msdyn_maskforcustomer) { this.dataMaskingRules = dataMaskingConfig.dataMaskingRules; } if (authSettings) { this.authSettings = authSettings; } preChatSurvey = liveWSAndLiveChatEngJoin.PreChatSurvey, msdyn_prechatenabled = liveWSAndLiveChatEngJoin.msdyn_prechatenabled, msdyn_callingoptions = liveWSAndLiveChatEngJoin.msdyn_callingoptions; isPreChatEnabled = msdyn_prechatenabled === true || msdyn_prechatenabled == "true"; if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) { this.preChatSurvey = preChatSurvey; } if (!this.authSettings) return [3 /*break*/, 4]; if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 3]; this.debug && console.log("OmnichannelChatSDK/getChatConfig/auth settings with auth and getAuthToken!", this.authSettings, this.chatSDKConfig.getAuthToken); return [4 /*yield*/, this.chatSDKConfig.getAuthToken()]; case 2: token = _a.sent(); if (token) { this.authenticatedUserToken = token; } else { console.warn("OmnichannelChatSDK/getChatConfig/auth, chat requires auth, but getAuthToken() returned null"); } return [3 /*break*/, 4]; case 3: console.warn("OmnichannelChatSDK/getChatConfig/auth, chat requires auth, but getAuthToken() is missing"); _a.label = 4; case 4: if (this.preChatSurvey) { this.debug && console.log('Prechat Survey!'); } this.callingOption = msdyn_callingoptions; this.liveChatConfig = liveChatConfig; return [2 /*return*/, this.liveChatConfig]; case 5: error_8 = _a.sent(); console.error("OmnichannelChatSDK/getChatConfig/error " + error_8); return [2 /*return*/, error_8]; case 6: return [2 /*return*/]; } }); }); }; return OmnichannelChatSDK; }()); exports.default = OmnichannelChatSDK; //# sourceMappingURL=OmnichannelChatSDK.js.map