@microsoft/omnichannel-chat-sdk 0.3.1-main.c96fb51 → 1.0.1-main.077d17c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +138 -66
  3. package/lib/OmnichannelChatSDK.d.ts +41 -24
  4. package/lib/OmnichannelChatSDK.js +1104 -408
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/api/createVoiceVideoCalling.js +6 -2
  7. package/lib/api/createVoiceVideoCalling.js.map +1 -1
  8. package/lib/config/settings.d.ts +2 -1
  9. package/lib/config/settings.js +3 -1
  10. package/lib/config/settings.js.map +1 -1
  11. package/lib/core/{IAuthSettings.d.ts → AuthSettings.d.ts} +1 -1
  12. package/lib/core/{IAuthSettings.js → AuthSettings.js} +1 -1
  13. package/lib/core/AuthSettings.js.map +1 -0
  14. package/lib/core/ChatConfig.d.ts +10 -0
  15. package/lib/core/{IChatConfig.js → ChatConfig.js} +1 -1
  16. package/lib/core/ChatConfig.js.map +1 -0
  17. package/lib/core/{IChatSDKConfig.d.ts → ChatSDKConfig.d.ts} +7 -7
  18. package/lib/core/{IChatSDKConfig.js → ChatSDKConfig.js} +1 -1
  19. package/lib/core/ChatSDKConfig.js.map +1 -0
  20. package/lib/core/ChatSDKExceptionDetails.d.ts +5 -0
  21. package/lib/core/ChatSDKExceptionDetails.js +3 -0
  22. package/lib/core/ChatSDKExceptionDetails.js.map +1 -0
  23. package/lib/core/ChatTranscriptBody.d.ts +5 -0
  24. package/lib/core/ChatTranscriptBody.js +3 -0
  25. package/lib/core/ChatTranscriptBody.js.map +1 -0
  26. package/lib/core/{ILiveChatContext.d.ts → LiveChatContext.d.ts} +1 -1
  27. package/lib/core/LiveChatContext.js +3 -0
  28. package/lib/core/LiveChatContext.js.map +1 -0
  29. package/lib/core/LiveChatVersion.d.ts +5 -0
  30. package/lib/core/LiveChatVersion.js +9 -0
  31. package/lib/core/LiveChatVersion.js.map +1 -0
  32. package/lib/core/LiveWorkItemDetails.d.ts +2 -0
  33. package/lib/core/{IOmnichannelConfig.d.ts → OmnichannelConfig.d.ts} +1 -1
  34. package/lib/core/OmnichannelConfig.js +3 -0
  35. package/lib/core/OmnichannelConfig.js.map +1 -0
  36. package/lib/core/OmnichannelErrorCodes.d.ts +4 -0
  37. package/lib/core/OmnichannelErrorCodes.js +8 -0
  38. package/lib/core/OmnichannelErrorCodes.js.map +1 -0
  39. package/lib/core/PostChatContext.d.ts +6 -0
  40. package/lib/core/PostChatContext.js +3 -0
  41. package/lib/core/PostChatContext.js.map +1 -0
  42. package/lib/core/{IStartChatOptionalParams.d.ts → StartChatOptionalParams.d.ts} +3 -3
  43. package/lib/core/StartChatOptionalParams.js +3 -0
  44. package/lib/core/StartChatOptionalParams.js.map +1 -0
  45. package/lib/core/messaging/ACSChatMessageType.d.ts +7 -0
  46. package/lib/core/messaging/ACSChatMessageType.js +11 -0
  47. package/lib/core/messaging/ACSChatMessageType.js.map +1 -0
  48. package/lib/core/messaging/ACSClient.d.ts +44 -0
  49. package/lib/core/messaging/ACSClient.js +588 -0
  50. package/lib/core/messaging/ACSClient.js.map +1 -0
  51. package/lib/core/messaging/ACSClientConfig.d.ts +4 -0
  52. package/lib/core/messaging/ACSClientConfig.js +3 -0
  53. package/lib/core/messaging/ACSClientConfig.js.map +1 -0
  54. package/lib/core/messaging/ACSParticipantDisplayName.d.ts +6 -0
  55. package/lib/core/messaging/ACSParticipantDisplayName.js +10 -0
  56. package/lib/core/messaging/ACSParticipantDisplayName.js.map +1 -0
  57. package/lib/core/messaging/ACSSessionInfo.d.ts +5 -0
  58. package/lib/core/messaging/ACSSessionInfo.js +3 -0
  59. package/lib/core/messaging/ACSSessionInfo.js.map +1 -0
  60. package/lib/core/{ChatAdapterConfig.d.ts → messaging/ChatAdapterConfig.d.ts} +2 -0
  61. package/lib/core/{ChatAdapterConfig.js → messaging/ChatAdapterConfig.js} +0 -0
  62. package/lib/core/messaging/ChatAdapterConfig.js.map +1 -0
  63. package/lib/core/messaging/ChatAdapterOptionalParams.d.ts +14 -0
  64. package/lib/core/messaging/ChatAdapterOptionalParams.js +3 -0
  65. package/lib/core/messaging/ChatAdapterOptionalParams.js.map +1 -0
  66. package/lib/core/{ChatAdapterProtocols.d.ts → messaging/ChatAdapterProtocols.d.ts} +1 -0
  67. package/lib/core/{ChatAdapterProtocols.js → messaging/ChatAdapterProtocols.js} +3 -1
  68. package/lib/core/messaging/ChatAdapterProtocols.js.map +1 -0
  69. package/lib/core/{IChatSDKMessage.d.ts → messaging/ChatSDKMessage.d.ts} +2 -1
  70. package/lib/core/messaging/ChatSDKMessage.js +3 -0
  71. package/lib/core/messaging/ChatSDKMessage.js.map +1 -0
  72. package/lib/core/{IC3Config.d.ts → messaging/IC3Config.d.ts} +0 -0
  73. package/lib/core/{IC3Config.js → messaging/IC3Config.js} +0 -0
  74. package/lib/core/messaging/IC3Config.js.map +1 -0
  75. package/lib/core/messaging/MessageTags.d.ts +3 -0
  76. package/lib/core/messaging/MessageTags.js +7 -0
  77. package/lib/core/messaging/MessageTags.js.map +1 -0
  78. package/lib/core/messaging/OmnichannelMessage.d.ts +64 -0
  79. package/lib/core/messaging/OmnichannelMessage.js +52 -0
  80. package/lib/core/messaging/OmnichannelMessage.js.map +1 -0
  81. package/lib/core/{OnNewMessageOptionalParams.d.ts → messaging/OnNewMessageOptionalParams.d.ts} +0 -0
  82. package/lib/core/{OnNewMessageOptionalParams.js → messaging/OnNewMessageOptionalParams.js} +0 -0
  83. package/lib/core/messaging/OnNewMessageOptionalParams.js.map +1 -0
  84. package/lib/external/ACSAdapter/AMSFileManager.d.ts +39 -0
  85. package/lib/external/ACSAdapter/AMSFileManager.js +306 -0
  86. package/lib/external/ACSAdapter/AMSFileManager.js.map +1 -0
  87. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.d.ts +5 -0
  88. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js +34 -0
  89. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js.map +1 -0
  90. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.d.ts +2 -0
  91. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js +31 -0
  92. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js.map +1 -0
  93. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.d.ts +2 -0
  94. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js +25 -0
  95. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js.map +1 -0
  96. package/lib/external/CallingSDK/ICallingSDKLogData.d.ts +7 -0
  97. package/lib/external/CallingSDK/ICallingSDKLogData.js +3 -0
  98. package/lib/external/CallingSDK/ICallingSDKLogData.js.map +1 -0
  99. package/lib/external/IC3Adapter/IChatToken.d.ts +2 -0
  100. package/lib/external/IC3Adapter/IIC3AdapterOptions.d.ts +12 -0
  101. package/lib/index.d.ts +7 -6
  102. package/lib/index.js +13 -8
  103. package/lib/index.js.map +1 -1
  104. package/lib/telemetry/AriaTelemetry.d.ts +4 -0
  105. package/lib/telemetry/AriaTelemetry.js +174 -4
  106. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  107. package/lib/telemetry/EventMarker.d.ts +3 -0
  108. package/lib/telemetry/EventMarker.js +13 -0
  109. package/lib/telemetry/EventMarker.js.map +1 -0
  110. package/lib/telemetry/ScenarioMarker.d.ts +11 -7
  111. package/lib/telemetry/ScenarioMarker.js +16 -7
  112. package/lib/telemetry/ScenarioMarker.js.map +1 -1
  113. package/lib/telemetry/ScenarioType.d.ts +3 -0
  114. package/lib/telemetry/ScenarioType.js +3 -0
  115. package/lib/telemetry/ScenarioType.js.map +1 -1
  116. package/lib/telemetry/TelemetryEvent.d.ts +7 -4
  117. package/lib/telemetry/TelemetryEvent.js +6 -10
  118. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  119. package/lib/tsconfig.tsbuildinfo +5186 -1323
  120. package/lib/utils/WebUtils.d.ts +3 -1
  121. package/lib/utils/WebUtils.js +8 -2
  122. package/lib/utils/WebUtils.js.map +1 -1
  123. package/lib/utils/createOmnichannelMessage.d.ts +11 -0
  124. package/lib/utils/createOmnichannelMessage.js +63 -0
  125. package/lib/utils/createOmnichannelMessage.js.map +1 -0
  126. package/lib/utils/libraries.d.ts +3 -1
  127. package/lib/utils/libraries.js +9 -2
  128. package/lib/utils/libraries.js.map +1 -1
  129. package/lib/utils/locale.d.ts +4 -0
  130. package/lib/utils/locale.js +61 -0
  131. package/lib/utils/locale.js.map +1 -0
  132. package/lib/utils/loggers.d.ts +67 -6
  133. package/lib/utils/loggers.js +289 -2
  134. package/lib/utils/loggers.js.map +1 -1
  135. package/lib/utils/utilities.js +10 -3
  136. package/lib/utils/utilities.js.map +1 -1
  137. package/lib/validators/OmnichannelConfigValidator.d.ts +2 -2
  138. package/lib/validators/OmnichannelConfigValidator.js.map +1 -1
  139. package/lib/validators/SDKConfigValidators.d.ts +3 -3
  140. package/lib/validators/SDKConfigValidators.js.map +1 -1
  141. package/package.json +5 -1
  142. package/lib/core/ChatAdapterConfig.js.map +0 -1
  143. package/lib/core/ChatAdapterProtocols.js.map +0 -1
  144. package/lib/core/IAuthSettings.js.map +0 -1
  145. package/lib/core/IC3Config.js.map +0 -1
  146. package/lib/core/IChatConfig.d.ts +0 -5
  147. package/lib/core/IChatConfig.js.map +0 -1
  148. package/lib/core/IChatSDKConfig.js.map +0 -1
  149. package/lib/core/IChatSDKMessage.js +0 -3
  150. package/lib/core/IChatSDKMessage.js.map +0 -1
  151. package/lib/core/IChatTranscriptBody.d.ts +0 -5
  152. package/lib/core/IChatTranscriptBody.js +0 -3
  153. package/lib/core/IChatTranscriptBody.js.map +0 -1
  154. package/lib/core/ILiveChatContext.js +0 -3
  155. package/lib/core/ILiveChatContext.js.map +0 -1
  156. package/lib/core/IOmnichannelConfig.js +0 -3
  157. package/lib/core/IOmnichannelConfig.js.map +0 -1
  158. package/lib/core/IStartChatOptionalParams.js +0 -3
  159. package/lib/core/IStartChatOptionalParams.js.map +0 -1
  160. package/lib/core/MessageTags.d.ts +0 -1
  161. package/lib/core/MessageTags.js +0 -5
  162. package/lib/core/MessageTags.js.map +0 -1
  163. package/lib/core/OnNewMessageOptionalParams.js.map +0 -1
@@ -55,35 +55,48 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
55
55
  return r;
56
56
  };
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
+ var loggers_1 = require("./utils/loggers");
59
+ var ACSClient_1 = require("./core/messaging/ACSClient");
60
+ var ocsdk_1 = require("@microsoft/ocsdk");
61
+ var locale_1 = require("./utils/locale");
62
+ var WebUtils_1 = require("./utils/WebUtils");
63
+ var platform_1 = require("./utils/platform");
64
+ var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
65
+ var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
66
+ var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
58
67
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
59
- var ChatAdapterProtocols_1 = require("./core/ChatAdapterProtocols");
68
+ var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
60
69
  var ConversationMode_1 = require("./core/ConversationMode");
61
- var loggers_1 = require("./utils/loggers");
62
- var createTelemetry_1 = require("./utils/createTelemetry");
63
- var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
64
- var MessageTags_1 = require("./core/MessageTags");
65
70
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
66
71
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
67
72
  var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
68
- var utilities_1 = require("./utils/utilities");
69
- var libraries_1 = require("./utils/libraries");
73
+ var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
74
+ var LiveChatVersion_1 = require("./core/LiveChatVersion");
70
75
  var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
71
- var WebUtils_1 = require("./utils/WebUtils");
72
76
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
73
77
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
78
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
74
79
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
75
- var platform_1 = require("./utils/platform");
76
80
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
77
81
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
78
- var ocsdk_1 = require("@microsoft/ocsdk");
79
- var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
80
82
  var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
83
+ var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
84
+ var createChannelDataEgressMiddleware_1 = require("./external/ACSAdapter/createChannelDataEgressMiddleware");
85
+ var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
86
+ var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
87
+ var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
88
+ var createTelemetry_1 = require("./utils/createTelemetry");
89
+ var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
90
+ var MessageTags_1 = require("./core/messaging/MessageTags");
91
+ var utilities_1 = require("./utils/utilities");
92
+ var libraries_1 = require("./utils/libraries");
81
93
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
82
- var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
83
94
  var OmnichannelChatSDK = /** @class */ (function () {
84
95
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
85
96
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
86
- var _a, _b, _c, _d, _e;
97
+ var _a, _b, _c, _d, _e, _f, _g, _h;
98
+ this.ACSClient = null;
99
+ this.AMSClient = null;
87
100
  this.authSettings = null;
88
101
  this.authenticatedUserToken = null;
89
102
  this.conversation = null;
@@ -91,15 +104,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
91
104
  this.telemetry = null;
92
105
  this.ic3ClientLogger = null;
93
106
  this.ocSdkLogger = null;
107
+ this.acsClientLogger = null;
108
+ this.acsAdapterLogger = null;
109
+ this.callingSdkLogger = null;
94
110
  this.isPersistentChat = false;
95
111
  this.isChatReconnect = false;
96
112
  this.reconnectId = null;
97
113
  this.refreshTokenTimer = null;
98
114
  this.debug = false;
115
+ this.runtimeId = ocsdk_1.uuidv4();
99
116
  this.omnichannelConfig = omnichannelConfig;
100
117
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
101
118
  );
102
119
  this.isInitialized = false;
120
+ this.liveChatVersion = LiveChatVersion_1.default.V1;
121
+ this.localeId = locale_1.defaultLocaleId;
103
122
  this.requestId = ocsdk_1.uuidv4();
104
123
  this.chatToken = {};
105
124
  this.liveChatConfig = {};
@@ -110,9 +129,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
110
129
  this.scenarioMarker = new ScenarioMarker_1.default(this.omnichannelConfig);
111
130
  this.ic3ClientLogger = loggers_1.createIC3ClientLogger(this.omnichannelConfig);
112
131
  this.ocSdkLogger = loggers_1.createOCSDKLogger(this.omnichannelConfig);
132
+ this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
133
+ this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
134
+ this.callingSdkLogger = loggers_1.createCallingSDKLogger(this.omnichannelConfig);
113
135
  this.scenarioMarker.useTelemetry(this.telemetry);
114
136
  this.ic3ClientLogger.useTelemetry(this.telemetry);
115
137
  this.ocSdkLogger.useTelemetry(this.telemetry);
138
+ this.acsClientLogger.useTelemetry(this.telemetry);
139
+ this.acsAdapterLogger.useTelemetry(this.telemetry);
140
+ this.callingSdkLogger.useTelemetry(this.telemetry);
141
+ this.scenarioMarker.setRuntimeId(this.runtimeId);
142
+ this.ic3ClientLogger.setRuntimeId(this.runtimeId);
143
+ this.ocSdkLogger.setRuntimeId(this.runtimeId);
144
+ this.acsClientLogger.setRuntimeId(this.runtimeId);
145
+ this.acsAdapterLogger.setRuntimeId(this.runtimeId);
146
+ this.callingSdkLogger.setRuntimeId(this.runtimeId);
116
147
  OmnichannelConfigValidator_1.default(omnichannelConfig);
117
148
  SDKConfigValidators_1.default(chatSDKConfig);
118
149
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -121,51 +152,71 @@ var OmnichannelChatSDK = /** @class */ (function () {
121
152
  }
122
153
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
123
154
  (_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setRequestId(this.requestId);
155
+ (_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
156
+ (_g = this.acsAdapterLogger) === null || _g === void 0 ? void 0 : _g.setRequestId(this.requestId);
157
+ (_h = this.callingSdkLogger) === null || _h === void 0 ? void 0 : _h.setRequestId(this.requestId);
124
158
  }
125
159
  /* istanbul ignore next */
126
160
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
127
- var _a, _b, _c;
161
+ var _a, _b, _c, _d, _e, _f, _g;
128
162
  this.debug = flag;
129
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
163
+ (_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
164
+ (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
130
165
  this.scenarioMarker.setDebug(flag);
131
- (_b = this.ic3ClientLogger) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
132
- (_c = this.ocSdkLogger) === null || _c === void 0 ? void 0 : _c.setDebug(flag);
166
+ (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setDebug(flag);
167
+ (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setDebug(flag);
168
+ (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
169
+ (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setDebug(flag);
170
+ (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setDebug(flag);
133
171
  };
134
172
  OmnichannelChatSDK.prototype.initialize = function () {
135
173
  return __awaiter(this, void 0, void 0, function () {
136
- var OCClient, IC3Client, _a;
137
- return __generator(this, function (_b) {
138
- switch (_b.label) {
174
+ var _a, _b, _c, _d;
175
+ return __generator(this, function (_e) {
176
+ switch (_e.label) {
139
177
  case 0:
140
178
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeChatSDK);
141
179
  if (this.isInitialized) {
142
180
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
143
181
  return [2 /*return*/, this.liveChatConfig];
144
182
  }
145
- _b.label = 1;
183
+ _e.label = 1;
146
184
  case 1:
147
- _b.trys.push([1, 5, , 6]);
185
+ _e.trys.push([1, 8, , 9]);
148
186
  this.OCSDKProvider = ocsdk_1.SDKProvider;
187
+ _a = this;
149
188
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, {}, this.ocSdkLogger)];
150
189
  case 2:
151
- OCClient = _b.sent();
152
- return [4 /*yield*/, this.getIC3Client()];
153
- case 3:
154
- IC3Client = _b.sent();
155
- // Assign & Update flag only if all dependencies have been initialized succesfully
156
- this.OCClient = OCClient;
157
- this.IC3Client = IC3Client;
190
+ _a.OCClient = _e.sent();
158
191
  return [4 /*yield*/, this.getChatConfig()];
192
+ case 3:
193
+ _e.sent();
194
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
195
+ this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
196
+ _b = this;
197
+ return [4 /*yield*/, omnichannel_amsclient_1.default({
198
+ framedMode: platform_1.isBrowser(),
199
+ debug: false,
200
+ logger: undefined
201
+ })];
159
202
  case 4:
160
- _b.sent();
203
+ _b.AMSClient = _e.sent();
204
+ return [3 /*break*/, 7];
205
+ case 5:
206
+ _c = this;
207
+ return [4 /*yield*/, this.getIC3Client()];
208
+ case 6:
209
+ _c.IC3Client = _e.sent();
210
+ _e.label = 7;
211
+ case 7:
161
212
  this.isInitialized = true;
162
213
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
163
- return [3 /*break*/, 6];
164
- case 5:
165
- _a = _b.sent();
214
+ return [3 /*break*/, 9];
215
+ case 8:
216
+ _d = _e.sent();
166
217
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDK);
167
- return [3 /*break*/, 6];
168
- case 6: return [2 /*return*/, this.liveChatConfig];
218
+ return [3 /*break*/, 9];
219
+ case 9: return [2 /*return*/, this.liveChatConfig];
169
220
  }
170
221
  });
171
222
  });
@@ -255,47 +306,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
255
306
  });
256
307
  };
257
308
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
258
- var _a, _b, _c, _d, _e, _f, _g, _h;
309
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
259
310
  if (optionalParams === void 0) { optionalParams = {}; }
260
311
  return __awaiter(this, void 0, void 0, function () {
261
- var reconnectableChatsParams, reconnectableChatsResponse, _j, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, error_4, exceptionDetails, _k, error_5, exceptionDetails;
312
+ var shouldReinitIC3Client, _t, reconnectableChatsParams, reconnectableChatsResponse, _u, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _v, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _w, error_8, exceptionDetails;
262
313
  var _this = this;
263
- return __generator(this, function (_l) {
264
- switch (_l.label) {
314
+ return __generator(this, function (_x) {
315
+ switch (_x.label) {
265
316
  case 0:
266
317
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
267
318
  RequestId: this.requestId
268
319
  });
320
+ shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
321
+ if (!shouldReinitIC3Client) return [3 /*break*/, 2];
322
+ _t = this;
323
+ return [4 /*yield*/, this.getIC3Client()];
324
+ case 1:
325
+ _t.IC3Client = _x.sent();
326
+ _x.label = 2;
327
+ case 2:
269
328
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
270
329
  this.reconnectId = optionalParams.reconnectId;
271
330
  }
272
- if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
273
- _l.label = 1;
274
- case 1:
275
- _l.trys.push([1, 3, , 4]);
331
+ if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
332
+ _x.label = 3;
333
+ case 3:
334
+ _x.trys.push([3, 5, , 6]);
276
335
  reconnectableChatsParams = {
277
336
  authenticatedUserToken: this.authenticatedUserToken
278
337
  };
279
338
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
280
- case 2:
281
- reconnectableChatsResponse = _l.sent();
339
+ case 4:
340
+ reconnectableChatsResponse = _x.sent();
282
341
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
283
342
  this.reconnectId = reconnectableChatsResponse.reconnectid;
284
343
  }
285
- return [3 /*break*/, 4];
286
- case 3:
287
- _j = _l.sent();
344
+ return [3 /*break*/, 6];
345
+ case 5:
346
+ _u = _x.sent();
288
347
  exceptionDetails = {
289
348
  response: "OCClientGetReconnectableChatsFailed"
290
349
  };
291
350
  throw Error(exceptionDetails.response);
292
- case 4:
293
- if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
351
+ case 6:
352
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
294
353
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
295
354
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
296
355
  return [4 /*yield*/, this.getConversationDetails()];
297
- case 5:
298
- conversationDetails = _l.sent();
356
+ case 7:
357
+ conversationDetails = _x.sent();
299
358
  if (Object.keys(conversationDetails).length === 0) {
300
359
  exceptionDetails = {
301
360
  response: "InvalidConversation"
@@ -320,23 +379,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
320
379
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
321
380
  throw Error(exceptionDetails.response);
322
381
  }
323
- _l.label = 6;
324
- case 6:
325
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
326
- return [4 /*yield*/, this.getChatToken(false)];
327
- case 7:
328
- _l.sent();
329
- _l.label = 8;
382
+ _x.label = 8;
330
383
  case 8:
384
+ if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
385
+ return [4 /*yield*/, this.getChatToken(false)];
386
+ case 9:
387
+ _x.sent();
388
+ _x.label = 10;
389
+ case 10:
331
390
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
332
391
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
392
+ (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
393
+ (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setChatId(this.chatToken.chatId || '');
394
+ (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId(this.chatToken.chatId || '');
333
395
  sessionInitOptionalParams = {
334
396
  initContext: {}
335
397
  };
336
- if (this.isPersistentChat && !((_e = this.chatSDKConfig.persistentChat) === null || _e === void 0 ? void 0 : _e.disable)) {
398
+ sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
399
+ if (this.isPersistentChat && !((_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.disable)) {
337
400
  sessionInitOptionalParams.reconnectId = this.reconnectId;
338
401
  }
339
- if (this.isChatReconnect && !((_f = this.chatSDKConfig.chatReconnect) === null || _f === void 0 ? void 0 : _f.disable) && !this.isPersistentChat) {
402
+ if (this.isChatReconnect && !((_j = this.chatSDKConfig.chatReconnect) === null || _j === void 0 ? void 0 : _j.disable) && !this.isPersistentChat) {
340
403
  sessionInitOptionalParams.reconnectId = this.reconnectId;
341
404
  }
342
405
  if (optionalParams.customContext) {
@@ -364,37 +427,121 @@ var OmnichannelChatSDK = /** @class */ (function () {
364
427
  if (this.authenticatedUserToken) {
365
428
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
366
429
  }
367
- _l.label = 9;
368
- case 9:
369
- _l.trys.push([9, 11, , 12]);
370
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
371
- case 10:
372
- _l.sent();
373
- return [3 /*break*/, 12];
430
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
431
+ _x.label = 11;
374
432
  case 11:
375
- error_3 = _l.sent();
433
+ _x.trys.push([11, 13, , 14]);
434
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
435
+ case 12:
436
+ _x.sent();
437
+ return [3 /*break*/, 14];
438
+ case 13:
439
+ error_3 = _x.sent();
376
440
  exceptionDetails = {
377
441
  response: "OCClientSessionInitFailed"
378
442
  };
443
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
444
+ if (((_k = error_3) === null || _k === void 0 ? void 0 : _k.isAxiosError) && ((_m = (_l = error_3.response) === null || _l === void 0 ? void 0 : _l.headers) === null || _m === void 0 ? void 0 : _m.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
445
+ exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
446
+ exceptionDetails.message = 'Widget used outside of operating hours';
447
+ console.error(exceptionDetails.message);
448
+ }
379
449
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
380
450
  RequestId: this.requestId,
381
451
  ChatId: this.chatToken.chatId,
382
452
  ExceptionDetails: JSON.stringify(exceptionDetails)
383
453
  });
384
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
385
- return [2 /*return*/, error_3];
386
- case 12:
387
- _l.trys.push([12, 14, , 15]);
454
+ throw new Error(exceptionDetails.response);
455
+ case 14:
456
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
457
+ chatAdapterConfig = {
458
+ token: this.chatToken.token,
459
+ id: this.chatToken.visitorId || 'teamsvisitor',
460
+ threadId: this.chatToken.chatId,
461
+ environmentUrl: this.chatToken.acsEndpoint,
462
+ pollingInterval: 1000
463
+ };
464
+ _x.label = 15;
465
+ case 15:
466
+ _x.trys.push([15, 17, , 18]);
467
+ return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.initialize({
468
+ token: chatAdapterConfig.token,
469
+ environmentUrl: chatAdapterConfig.environmentUrl
470
+ }))];
471
+ case 16:
472
+ _x.sent();
473
+ return [3 /*break*/, 18];
474
+ case 17:
475
+ error_4 = _x.sent();
476
+ exceptionDetails = {
477
+ response: "ACSClientInitializeFailed"
478
+ };
479
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
480
+ RequestId: this.requestId,
481
+ ChatId: this.chatToken.chatId,
482
+ ExceptionDetails: JSON.stringify(exceptionDetails)
483
+ });
484
+ console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
485
+ return [2 /*return*/, error_4];
486
+ case 18:
487
+ _x.trys.push([18, 20, , 21]);
488
+ _v = this;
489
+ return [4 /*yield*/, ((_p = this.ACSClient) === null || _p === void 0 ? void 0 : _p.joinConversation({
490
+ id: chatAdapterConfig.id,
491
+ threadId: chatAdapterConfig.threadId,
492
+ pollingInterval: chatAdapterConfig.pollingInterval
493
+ }))];
494
+ case 19:
495
+ _v.conversation = (_x.sent());
496
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
497
+ RequestId: this.requestId,
498
+ ChatId: this.chatToken.chatId
499
+ });
500
+ return [3 /*break*/, 21];
501
+ case 20:
502
+ error_5 = _x.sent();
503
+ exceptionDetails = {
504
+ response: "ACSClientJoinConversationFailed"
505
+ };
506
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
507
+ RequestId: this.requestId,
508
+ ChatId: this.chatToken.chatId,
509
+ ExceptionDetails: JSON.stringify(exceptionDetails)
510
+ });
511
+ console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
512
+ throw Error(exceptionDetails.response);
513
+ case 21:
514
+ _x.trys.push([21, 23, , 24]);
515
+ return [4 /*yield*/, ((_q = this.AMSClient) === null || _q === void 0 ? void 0 : _q.initialize({
516
+ chatToken: this.chatToken
517
+ }))];
518
+ case 22:
519
+ _x.sent();
520
+ return [3 /*break*/, 24];
521
+ case 23:
522
+ error_6 = _x.sent();
523
+ exceptionDetails = {
524
+ response: "AMSClientInitializeFailed"
525
+ };
526
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
527
+ RequestId: this.requestId,
528
+ ChatId: this.chatToken.chatId,
529
+ ExceptionDetails: JSON.stringify(exceptionDetails)
530
+ });
531
+ throw Error(exceptionDetails.response);
532
+ case 24: return [3 /*break*/, 31];
533
+ case 25:
534
+ _x.trys.push([25, 27, , 28]);
388
535
  return [4 /*yield*/, this.IC3Client.initialize({
389
536
  token: this.chatToken.token,
390
537
  regionGtms: this.chatToken.regionGTMS,
391
538
  visitor: true
392
539
  })];
393
- case 13:
394
- _l.sent();
395
- return [3 /*break*/, 15];
396
- case 14:
397
- error_4 = _l.sent();
540
+ case 26:
541
+ _x.sent();
542
+ return [3 /*break*/, 28];
543
+ case 27:
544
+ error_7 = _x.sent();
398
545
  exceptionDetails = {
399
546
  response: "IC3ClientInitializeFailed"
400
547
  };
@@ -403,21 +550,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
403
550
  ChatId: this.chatToken.chatId,
404
551
  ExceptionDetails: JSON.stringify(exceptionDetails)
405
552
  });
406
- console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
407
- return [2 /*return*/, error_4];
408
- case 15:
409
- _l.trys.push([15, 17, , 18]);
410
- _k = this;
553
+ console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
554
+ return [2 /*return*/, error_7];
555
+ case 28:
556
+ _x.trys.push([28, 30, , 31]);
557
+ _w = this;
411
558
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
412
- case 16:
413
- _k.conversation = _l.sent();
559
+ case 29:
560
+ _w.conversation = _x.sent();
414
561
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
415
562
  RequestId: this.requestId,
416
563
  ChatId: this.chatToken.chatId
417
564
  });
418
- return [3 /*break*/, 18];
419
- case 17:
420
- error_5 = _l.sent();
565
+ return [3 /*break*/, 31];
566
+ case 30:
567
+ error_8 = _x.sent();
421
568
  exceptionDetails = {
422
569
  response: "IC3ClientJoinConversationFailed"
423
570
  };
@@ -426,10 +573,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
426
573
  ChatId: this.chatToken.chatId,
427
574
  ExceptionDetails: JSON.stringify(exceptionDetails)
428
575
  });
429
- console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
430
- return [2 /*return*/, error_5];
431
- case 18:
432
- if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
576
+ console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
577
+ return [2 /*return*/, error_8];
578
+ case 31:
579
+ if (this.isPersistentChat && !((_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.disable)) {
433
580
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
434
581
  return __generator(this, function (_a) {
435
582
  switch (_a.label) {
@@ -440,7 +587,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
440
587
  return [2 /*return*/];
441
588
  }
442
589
  });
443
- }); }, (_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.tokenUpdateTime);
590
+ }); }, (_s = this.chatSDKConfig.persistentChat) === null || _s === void 0 ? void 0 : _s.tokenUpdateTime);
444
591
  }
445
592
  return [2 /*return*/];
446
593
  }
@@ -448,11 +595,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
448
595
  });
449
596
  };
450
597
  OmnichannelChatSDK.prototype.endChat = function () {
451
- var _a, _b, _c, _d, _e, _f, _g;
598
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
452
599
  return __awaiter(this, void 0, void 0, function () {
453
- var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_6, exceptionDetails;
454
- return __generator(this, function (_h) {
455
- switch (_h.label) {
600
+ var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
601
+ return __generator(this, function (_p) {
602
+ switch (_p.label) {
456
603
  case 0:
457
604
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
458
605
  RequestId: this.requestId,
@@ -466,17 +613,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
466
613
  }
467
614
  if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
468
615
  isChatReconnect = this.reconnectId !== null ? true : false;
616
+ this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
469
617
  sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
470
618
  }
471
619
  if (this.authenticatedUserToken) {
472
620
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
473
621
  }
474
- _h.label = 1;
622
+ _p.label = 1;
475
623
  case 1:
476
- _h.trys.push([1, 3, , 4]);
624
+ _p.trys.push([1, 3, , 4]);
477
625
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
478
626
  case 2:
479
- _h.sent();
627
+ _p.sent();
480
628
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
481
629
  RequestId: this.requestId,
482
630
  ChatId: this.chatToken.chatId
@@ -486,13 +634,24 @@ var OmnichannelChatSDK = /** @class */ (function () {
486
634
  this.requestId = ocsdk_1.uuidv4();
487
635
  this.chatToken = {};
488
636
  this.reconnectId = null;
637
+ if (this.IC3Client) {
638
+ this.IC3Client.dispose();
639
+ !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
640
+ this.IC3Client = null;
641
+ }
489
642
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
490
643
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
491
644
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
492
645
  (_g = this.ocSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId('');
646
+ (_h = this.acsClientLogger) === null || _h === void 0 ? void 0 : _h.setRequestId(this.requestId);
647
+ (_j = this.acsClientLogger) === null || _j === void 0 ? void 0 : _j.setChatId('');
648
+ (_k = this.acsAdapterLogger) === null || _k === void 0 ? void 0 : _k.setRequestId(this.requestId);
649
+ (_l = this.acsAdapterLogger) === null || _l === void 0 ? void 0 : _l.setChatId('');
650
+ (_m = this.callingSdkLogger) === null || _m === void 0 ? void 0 : _m.setRequestId(this.requestId);
651
+ (_o = this.callingSdkLogger) === null || _o === void 0 ? void 0 : _o.setChatId('');
493
652
  return [3 /*break*/, 4];
494
653
  case 3:
495
- error_6 = _h.sent();
654
+ error_9 = _p.sent();
496
655
  exceptionDetails = {
497
656
  response: "OCClientSessionCloseFailed"
498
657
  };
@@ -501,8 +660,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
501
660
  ChatId: this.chatToken.chatId,
502
661
  ExceptionDetails: JSON.stringify(exceptionDetails),
503
662
  });
504
- console.error("OmnichannelChatSDK/endChat/error " + error_6);
505
- return [2 /*return*/, error_6];
663
+ console.error("OmnichannelChatSDK/endChat/error " + error_9);
664
+ return [2 /*return*/, error_9];
506
665
  case 4:
507
666
  if (this.refreshTokenTimer !== null) {
508
667
  clearInterval(this.refreshTokenTimer);
@@ -522,6 +681,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
522
681
  case 1:
523
682
  chatToken = _a.sent();
524
683
  requestId = this.requestId;
684
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetCurrentLiveChatContext, {
685
+ RequestId: requestId,
686
+ ChatId: chatToken.chatId
687
+ });
525
688
  chatSession = {
526
689
  chatToken: chatToken,
527
690
  requestId: requestId
@@ -529,29 +692,43 @@ var OmnichannelChatSDK = /** @class */ (function () {
529
692
  if (Object.keys(chatSession.chatToken).length === 0) {
530
693
  return [2 /*return*/, {}];
531
694
  }
695
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetCurrentLiveChatContext, {
696
+ RequestId: requestId,
697
+ ChatId: chatToken.chatId
698
+ });
532
699
  return [2 /*return*/, chatSession];
533
700
  }
534
701
  });
535
702
  });
536
703
  };
537
704
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
538
- var _a, _b;
705
+ var _a, _b, _c, _d;
539
706
  return __awaiter(this, void 0, void 0, function () {
540
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_7;
541
- return __generator(this, function (_c) {
542
- switch (_c.label) {
707
+ var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_10;
708
+ return __generator(this, function (_e) {
709
+ switch (_e.label) {
543
710
  case 0:
544
711
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
545
712
  RequestId: this.requestId,
546
713
  ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
547
714
  });
548
- _c.label = 1;
715
+ getLWIDetailsOptionalParams = {};
716
+ if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
717
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
718
+ }
719
+ if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
720
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
721
+ }
722
+ if (this.authenticatedUserToken) {
723
+ getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
724
+ }
725
+ _e.label = 1;
549
726
  case 1:
550
- _c.trys.push([1, 3, , 4]);
551
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
727
+ _e.trys.push([1, 3, , 4]);
728
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
552
729
  case 2:
553
- lwiDetails = _c.sent();
554
- state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
730
+ lwiDetails = _e.sent();
731
+ state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn, canRenderPostChat = lwiDetails.CanRenderPostChat, participantType = lwiDetails.ParticipantType;
555
732
  liveWorkItemDetails = {
556
733
  state: state,
557
734
  conversationId: conversationId
@@ -559,18 +736,24 @@ var OmnichannelChatSDK = /** @class */ (function () {
559
736
  if (agentAcceptedOn) {
560
737
  liveWorkItemDetails.agentAcceptedOn = agentAcceptedOn;
561
738
  }
739
+ if (canRenderPostChat) {
740
+ liveWorkItemDetails.canRenderPostChat = canRenderPostChat;
741
+ }
742
+ if (participantType) {
743
+ liveWorkItemDetails.participantType = participantType;
744
+ }
562
745
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
563
746
  RequestId: this.requestId,
564
- ChatId: ((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId) || '',
747
+ ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
565
748
  });
566
749
  return [2 /*return*/, liveWorkItemDetails];
567
750
  case 3:
568
- error_7 = _c.sent();
751
+ error_10 = _e.sent();
569
752
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
570
753
  RequestId: this.requestId,
571
754
  ChatId: this.chatToken.chatId || '',
572
755
  });
573
- console.error("OmnichannelChatSDK/getConversationDetails/error " + error_7);
756
+ console.error("OmnichannelChatSDK/getConversationDetails/error " + error_10);
574
757
  return [3 /*break*/, 4];
575
758
  case 4: return [2 /*return*/, {}];
576
759
  }
@@ -614,7 +797,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
614
797
  var _a, _b;
615
798
  if (cached === void 0) { cached = true; }
616
799
  return __awaiter(this, void 0, void 0, function () {
617
- var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, error_8, exceptionDetails;
800
+ var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, acsEndpoint, attachmentConfiguration, error_11, exceptionDetails;
618
801
  return __generator(this, function (_c) {
619
802
  switch (_c.label) {
620
803
  case 0:
@@ -638,7 +821,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
638
821
  return [4 /*yield*/, this.OCClient.getChatToken(this.requestId, getChatTokenOptionalParams)];
639
822
  case 2:
640
823
  chatToken = _c.sent();
641
- chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken;
824
+ chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken, acsEndpoint = chatToken.ACSEndpoint, attachmentConfiguration = chatToken.AttachmentConfiguration;
642
825
  this.chatToken = {
643
826
  chatId: chatId,
644
827
  regionGTMS: JSON.parse(regionGtms),
@@ -646,15 +829,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
646
829
  token: token,
647
830
  expiresIn: expiresIn,
648
831
  visitorId: visitorId,
649
- voiceVideoCallToken: voiceVideoCallToken
832
+ voiceVideoCallToken: voiceVideoCallToken,
833
+ acsEndpoint: acsEndpoint,
650
834
  };
835
+ if (attachmentConfiguration && attachmentConfiguration.AttachmentServiceEndpoint) {
836
+ this.chatToken.amsEndpoint = attachmentConfiguration.AttachmentServiceEndpoint;
837
+ }
651
838
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetChatToken, {
652
839
  RequestId: this.requestId,
653
840
  ChatId: this.chatToken.chatId
654
841
  });
655
842
  return [3 /*break*/, 4];
656
843
  case 3:
657
- error_8 = _c.sent();
844
+ error_11 = _c.sent();
658
845
  exceptionDetails = {
659
846
  response: "OCClientGetChatTokenFailed"
660
847
  };
@@ -663,7 +850,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
663
850
  ChatId: this.chatToken.chatId,
664
851
  ExceptionDetails: JSON.stringify(exceptionDetails),
665
852
  });
666
- console.error("OmnichannelChatSDK/getChatToken/error " + error_8);
853
+ console.error("OmnichannelChatSDK/getChatToken/error " + error_11);
667
854
  return [3 /*break*/, 4];
668
855
  case 4: return [3 /*break*/, 6];
669
856
  case 5:
@@ -684,11 +871,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
684
871
  return [2 /*return*/, ''];
685
872
  }
686
873
  if (this.chatToken.voiceVideoCallToken) {
687
- console.log("calling:acs");
874
+ /* istanbul ignore next */
875
+ this.debug && console.log("calling:acs");
688
876
  return [2 /*return*/, this.chatToken.voiceVideoCallToken.Token];
689
877
  }
690
878
  else {
691
- console.log("calling:skype");
879
+ /* istanbul ignore next */
880
+ this.debug && console.log("calling:skype");
692
881
  return [2 /*return*/, this.chatToken.token];
693
882
  }
694
883
  return [2 /*return*/];
@@ -698,8 +887,34 @@ var OmnichannelChatSDK = /** @class */ (function () {
698
887
  OmnichannelChatSDK.prototype.getMessages = function () {
699
888
  var _a;
700
889
  return __awaiter(this, void 0, void 0, function () {
701
- return __generator(this, function (_b) {
702
- return [2 /*return*/, (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.getMessages()];
890
+ var messages, _b;
891
+ return __generator(this, function (_c) {
892
+ switch (_c.label) {
893
+ case 0:
894
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetMessages, {
895
+ RequestId: this.requestId,
896
+ ChatId: this.chatToken.chatId
897
+ });
898
+ _c.label = 1;
899
+ case 1:
900
+ _c.trys.push([1, 3, , 4]);
901
+ return [4 /*yield*/, ((_a = this.conversation) === null || _a === void 0 ? void 0 : _a.getMessages())];
902
+ case 2:
903
+ messages = _c.sent();
904
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetMessages, {
905
+ RequestId: this.requestId,
906
+ ChatId: this.chatToken.chatId
907
+ });
908
+ return [2 /*return*/, messages];
909
+ case 3:
910
+ _b = _c.sent();
911
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetMessages, {
912
+ RequestId: this.requestId,
913
+ ChatId: this.chatToken.chatId
914
+ });
915
+ return [3 /*break*/, 4];
916
+ case 4: return [2 /*return*/];
917
+ }
703
918
  });
704
919
  });
705
920
  };
@@ -711,149 +926,334 @@ var OmnichannelChatSDK = /** @class */ (function () {
711
926
  });
712
927
  };
713
928
  OmnichannelChatSDK.prototype.sendMessage = function (message) {
714
- return __awaiter(this, void 0, void 0, function () {
715
- var _a, disable, maskingCharacter, content, _i, _b, maskingRule, regex, match, replaceStr, messageToSend;
716
- return __generator(this, function (_c) {
717
- _a = this.chatSDKConfig.dataMasking, disable = _a.disable, maskingCharacter = _a.maskingCharacter;
718
- content = message.content;
719
- if (Object.keys(this.dataMaskingRules).length > 0 && !disable) {
720
- for (_i = 0, _b = Object.values(this.dataMaskingRules); _i < _b.length; _i++) {
721
- maskingRule = _b[_i];
722
- regex = new RegExp(maskingRule, 'g');
723
- match = void 0;
724
- while (match = regex.exec(content)) { // eslint-disable-line no-cond-assign
725
- replaceStr = match[0].replace(/./g, maskingCharacter);
726
- content = content.replace(match[0], replaceStr);
727
- }
728
- }
729
- }
730
- message.content = content;
731
- messageToSend = {
732
- content: message.content,
733
- timestamp: new Date(),
734
- contentType: MessageContentType_1.default.Text,
735
- deliveryMode: DeliveryMode_1.default.Bridged,
736
- messageType: MessageType_1.default.UserMessage,
737
- properties: undefined,
738
- tags: __spreadArrays(MessageTags_1.defaultMessageTags),
739
- sender: {
740
- displayName: "Customer",
741
- id: "customer",
742
- type: PersonType_1.default.User
743
- }
744
- };
745
- if (message.tags) {
746
- messageToSend.tags = message.tags;
747
- }
748
- if (message.timestamp) {
749
- messageToSend.timestamp = message.timestamp;
750
- }
751
- return [2 /*return*/, this.conversation.sendMessage(messageToSend)];
752
- });
753
- });
754
- };
755
- OmnichannelChatSDK.prototype.onNewMessage = function (onNewMessageCallback, optionalParams) {
756
929
  var _a;
757
- if (optionalParams === void 0) { optionalParams = {}; }
758
930
  return __awaiter(this, void 0, void 0, function () {
759
- var postedMessages, messages, _i, _b, message, clientmessageid;
760
- return __generator(this, function (_c) {
761
- switch (_c.label) {
931
+ var _b, disable, maskingCharacter, content, _i, _c, maskingRule, regex, match, replaceStr, sendMessageRequest, error_12, messageToSend, _d;
932
+ return __generator(this, function (_e) {
933
+ switch (_e.label) {
762
934
  case 0:
763
- postedMessages = new Set();
764
- if (!optionalParams.rehydrate) return [3 /*break*/, 2];
765
- this.debug && console.log('[OmnichannelChatSDK][onNewMessage] rehydrate');
766
- return [4 /*yield*/, this.getMessages()];
767
- case 1:
768
- messages = _c.sent();
769
- if (messages) {
770
- for (_i = 0, _b = messages.reverse(); _i < _b.length; _i++) {
771
- message = _b[_i];
772
- clientmessageid = message.clientmessageid;
773
- if (postedMessages.has(clientmessageid)) {
774
- continue;
935
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.SendMessages, {
936
+ RequestId: this.requestId,
937
+ ChatId: this.chatToken.chatId
938
+ });
939
+ _b = this.chatSDKConfig.dataMasking, disable = _b.disable, maskingCharacter = _b.maskingCharacter;
940
+ content = message.content;
941
+ if (Object.keys(this.dataMaskingRules).length > 0 && !disable) {
942
+ for (_i = 0, _c = Object.values(this.dataMaskingRules); _i < _c.length; _i++) {
943
+ maskingRule = _c[_i];
944
+ regex = new RegExp(maskingRule, 'g');
945
+ match = void 0;
946
+ while (match = regex.exec(content)) { // eslint-disable-line no-cond-assign
947
+ replaceStr = match[0].replace(/./g, maskingCharacter);
948
+ content = content.replace(match[0], replaceStr);
775
949
  }
776
- postedMessages.add(clientmessageid);
777
- onNewMessageCallback(message);
778
950
  }
779
951
  }
780
- _c.label = 2;
952
+ message.content = content;
953
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
954
+ sendMessageRequest = {
955
+ content: message.content,
956
+ };
957
+ sendMessageRequest.metadata = {
958
+ widgetId: this.omnichannelConfig.widgetId,
959
+ clientMessageId: Date.now().toString()
960
+ };
961
+ if (message.metadata) {
962
+ sendMessageRequest.metadata = __assign(__assign({}, sendMessageRequest.metadata), message.metadata);
963
+ }
964
+ _e.label = 1;
965
+ case 1:
966
+ _e.trys.push([1, 3, , 4]);
967
+ return [4 /*yield*/, ((_a = this.conversation) === null || _a === void 0 ? void 0 : _a.sendMessage(sendMessageRequest))];
781
968
  case 2:
782
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) {
783
- var clientmessageid = message.clientmessageid, messageType = message.messageType;
784
- // Filter out customer messages
785
- if (utilities_1.isCustomerMessage(message)) {
786
- return;
787
- }
788
- // Skip duplicates
789
- if (postedMessages.has(clientmessageid)) {
790
- return;
791
- }
792
- if (messageType !== MessageType_1.default.Typing) {
793
- onNewMessageCallback(message);
794
- }
795
- });
796
- return [2 /*return*/];
797
- }
798
- });
799
- });
800
- };
801
- OmnichannelChatSDK.prototype.sendTypingEvent = function () {
802
- return __awaiter(this, void 0, void 0, function () {
803
- var typingPayload, members, botMembers, error_9;
804
- return __generator(this, function (_a) {
805
- switch (_a.label) {
806
- case 0:
807
- typingPayload = "{isTyping: 0}";
808
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.SendTypingEvent, {
969
+ _e.sent();
970
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
809
971
  RequestId: this.requestId,
810
972
  ChatId: this.chatToken.chatId
811
973
  });
812
- _a.label = 1;
813
- case 1:
814
- _a.trys.push([1, 5, , 6]);
815
- return [4 /*yield*/, this.conversation.indicateTypingStatus(0)];
816
- case 2:
817
- _a.sent();
818
- return [4 /*yield*/, this.conversation.getMembers()];
974
+ return [3 /*break*/, 4];
819
975
  case 3:
820
- members = _a.sent();
821
- botMembers = members.filter(function (member) { return member.type === PersonType_1.default.Bot; });
822
- return [4 /*yield*/, this.conversation.sendMessageToBot(botMembers[0].id, { payload: typingPayload })];
823
- case 4:
824
- _a.sent();
825
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendTypingEvent, {
976
+ error_12 = _e.sent();
977
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
826
978
  RequestId: this.requestId,
827
979
  ChatId: this.chatToken.chatId
828
980
  });
829
- return [3 /*break*/, 6];
981
+ throw new Error('ChatSDKSendMessageFailed');
982
+ case 4: return [3 /*break*/, 9];
830
983
  case 5:
831
- error_9 = _a.sent();
832
- console.error("OmnichannelChatSDK/sendTypingEvent/error");
833
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
984
+ messageToSend = {
985
+ content: message.content,
986
+ timestamp: new Date(),
987
+ contentType: MessageContentType_1.default.Text,
988
+ deliveryMode: DeliveryMode_1.default.Bridged,
989
+ messageType: MessageType_1.default.UserMessage,
990
+ properties: undefined,
991
+ tags: __spreadArrays(MessageTags_1.defaultMessageTags),
992
+ sender: {
993
+ displayName: "Customer",
994
+ id: "customer",
995
+ type: PersonType_1.default.User
996
+ }
997
+ };
998
+ if (message.tags) {
999
+ messageToSend.tags = message.tags;
1000
+ }
1001
+ if (message.timestamp) {
1002
+ messageToSend.timestamp = message.timestamp;
1003
+ }
1004
+ _e.label = 6;
1005
+ case 6:
1006
+ _e.trys.push([6, 8, , 9]);
1007
+ return [4 /*yield*/, this.conversation.sendMessage(messageToSend)];
1008
+ case 7:
1009
+ _e.sent();
1010
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
834
1011
  RequestId: this.requestId,
835
1012
  ChatId: this.chatToken.chatId
836
1013
  });
837
- return [2 /*return*/, error_9];
838
- case 6: return [2 /*return*/];
1014
+ return [3 /*break*/, 9];
1015
+ case 8:
1016
+ _d = _e.sent();
1017
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1018
+ RequestId: this.requestId,
1019
+ ChatId: this.chatToken.chatId
1020
+ });
1021
+ throw new Error('ChatSDKSendMessageFailed');
1022
+ case 9: return [2 /*return*/];
839
1023
  }
840
1024
  });
841
1025
  });
842
1026
  };
843
- OmnichannelChatSDK.prototype.onTypingEvent = function (onTypingEventCallback) {
844
- var _a;
1027
+ OmnichannelChatSDK.prototype.onNewMessage = function (onNewMessageCallback, optionalParams) {
1028
+ var _a, _b;
1029
+ if (optionalParams === void 0) { optionalParams = {}; }
845
1030
  return __awaiter(this, void 0, void 0, function () {
846
- return __generator(this, function (_b) {
847
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) {
848
- var messageType = message.messageType;
849
- // Filter out customer messages
850
- if (utilities_1.isCustomerMessage(message)) {
851
- return;
852
- }
853
- if (messageType === MessageType_1.default.Typing) {
854
- onTypingEventCallback(message);
855
- }
1031
+ var postedMessages_1, messages, _i, _c, message, id, postedMessages_2, messages, _d, _e, message, clientmessageid, omnichannelMessage;
1032
+ var _this = this;
1033
+ return __generator(this, function (_f) {
1034
+ switch (_f.label) {
1035
+ case 0:
1036
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnNewMessage, {
1037
+ RequestId: this.requestId,
1038
+ ChatId: this.chatToken.chatId
1039
+ });
1040
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 3];
1041
+ postedMessages_1 = new Set();
1042
+ if (!optionalParams.rehydrate) return [3 /*break*/, 2];
1043
+ this.debug && console.log('[OmnichannelChatSDK][onNewMessage] rehydrate');
1044
+ return [4 /*yield*/, this.getMessages()];
1045
+ case 1:
1046
+ messages = _f.sent();
1047
+ for (_i = 0, _c = messages.reverse(); _i < _c.length; _i++) {
1048
+ message = _c[_i];
1049
+ id = message.id;
1050
+ if (postedMessages_1.has(id)) {
1051
+ continue;
1052
+ }
1053
+ postedMessages_1.add(id);
1054
+ onNewMessageCallback(message);
1055
+ }
1056
+ _f.label = 2;
1057
+ case 2:
1058
+ try {
1059
+ (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (event) {
1060
+ var id = event.id;
1061
+ var omnichannelMessage = createOmnichannelMessage_1.default(event, {
1062
+ liveChatVersion: _this.liveChatVersion,
1063
+ debug: _this.debug
1064
+ });
1065
+ if (!postedMessages_1.has(id)) {
1066
+ onNewMessageCallback(omnichannelMessage);
1067
+ postedMessages_1.add(id);
1068
+ }
1069
+ });
1070
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnNewMessage, {
1071
+ RequestId: this.requestId,
1072
+ ChatId: this.chatToken.chatId
1073
+ });
1074
+ }
1075
+ catch (_g) {
1076
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnNewMessage, {
1077
+ RequestId: this.requestId,
1078
+ ChatId: this.chatToken.chatId
1079
+ });
1080
+ }
1081
+ return [3 /*break*/, 6];
1082
+ case 3:
1083
+ postedMessages_2 = new Set();
1084
+ if (!optionalParams.rehydrate) return [3 /*break*/, 5];
1085
+ this.debug && console.log('[OmnichannelChatSDK][onNewMessage] rehydrate');
1086
+ return [4 /*yield*/, this.getMessages()];
1087
+ case 4:
1088
+ messages = _f.sent();
1089
+ if (messages) {
1090
+ for (_d = 0, _e = messages.reverse(); _d < _e.length; _d++) {
1091
+ message = _e[_d];
1092
+ clientmessageid = message.clientmessageid;
1093
+ if (postedMessages_2.has(clientmessageid)) {
1094
+ continue;
1095
+ }
1096
+ postedMessages_2.add(clientmessageid);
1097
+ omnichannelMessage = createOmnichannelMessage_1.default(message, {
1098
+ liveChatVersion: this.liveChatVersion,
1099
+ debug: this.debug
1100
+ });
1101
+ onNewMessageCallback(omnichannelMessage);
1102
+ }
1103
+ }
1104
+ _f.label = 5;
1105
+ case 5:
1106
+ try {
1107
+ (_b = this.conversation) === null || _b === void 0 ? void 0 : _b.registerOnNewMessage(function (message) {
1108
+ var clientmessageid = message.clientmessageid, messageType = message.messageType;
1109
+ // Filter out customer messages
1110
+ if (utilities_1.isCustomerMessage(message)) {
1111
+ return;
1112
+ }
1113
+ // Skip duplicates
1114
+ if (postedMessages_2.has(clientmessageid)) {
1115
+ return;
1116
+ }
1117
+ if (messageType !== MessageType_1.default.Typing) {
1118
+ var omnichannelMessage = createOmnichannelMessage_1.default(message, {
1119
+ liveChatVersion: _this.liveChatVersion,
1120
+ debug: _this.debug
1121
+ });
1122
+ onNewMessageCallback(omnichannelMessage);
1123
+ }
1124
+ });
1125
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnNewMessage, {
1126
+ RequestId: this.requestId,
1127
+ ChatId: this.chatToken.chatId
1128
+ });
1129
+ }
1130
+ catch (_h) {
1131
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnNewMessage, {
1132
+ RequestId: this.requestId,
1133
+ ChatId: this.chatToken.chatId
1134
+ });
1135
+ }
1136
+ _f.label = 6;
1137
+ case 6: return [2 /*return*/];
1138
+ }
1139
+ });
1140
+ });
1141
+ };
1142
+ OmnichannelChatSDK.prototype.sendTypingEvent = function () {
1143
+ return __awaiter(this, void 0, void 0, function () {
1144
+ var error_13, typingPayload, members, botMembers, error_14;
1145
+ return __generator(this, function (_a) {
1146
+ switch (_a.label) {
1147
+ case 0:
1148
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.SendTypingEvent, {
1149
+ RequestId: this.requestId,
1150
+ ChatId: this.chatToken.chatId
1151
+ });
1152
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 6];
1153
+ _a.label = 1;
1154
+ case 1:
1155
+ _a.trys.push([1, 4, , 5]);
1156
+ return [4 /*yield*/, this.OCClient.sendTypingIndicator(this.requestId, LiveChatVersion_1.default.V2, {
1157
+ customerDisplayName: ACSParticipantDisplayName_1.default.Customer
1158
+ })];
1159
+ case 2:
1160
+ _a.sent();
1161
+ return [4 /*yield*/, this.conversation.sendTyping()];
1162
+ case 3:
1163
+ _a.sent();
1164
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendTypingEvent, {
1165
+ RequestId: this.requestId,
1166
+ ChatId: this.chatToken.chatId
1167
+ });
1168
+ return [3 /*break*/, 5];
1169
+ case 4:
1170
+ error_13 = _a.sent();
1171
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1172
+ RequestId: this.requestId,
1173
+ ChatId: this.chatToken.chatId
1174
+ });
1175
+ throw new Error('OCClientSendTypingFailed');
1176
+ case 5: return [3 /*break*/, 12];
1177
+ case 6:
1178
+ typingPayload = "{isTyping: 0}";
1179
+ _a.label = 7;
1180
+ case 7:
1181
+ _a.trys.push([7, 11, , 12]);
1182
+ return [4 /*yield*/, this.conversation.indicateTypingStatus(0)];
1183
+ case 8:
1184
+ _a.sent();
1185
+ return [4 /*yield*/, this.conversation.getMembers()];
1186
+ case 9:
1187
+ members = _a.sent();
1188
+ botMembers = members.filter(function (member) { return member.type === PersonType_1.default.Bot; });
1189
+ return [4 /*yield*/, this.conversation.sendMessageToBot(botMembers[0].id, { payload: typingPayload })];
1190
+ case 10:
1191
+ _a.sent();
1192
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendTypingEvent, {
1193
+ RequestId: this.requestId,
1194
+ ChatId: this.chatToken.chatId
1195
+ });
1196
+ return [3 /*break*/, 12];
1197
+ case 11:
1198
+ error_14 = _a.sent();
1199
+ console.error("OmnichannelChatSDK/sendTypingEvent/error");
1200
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1201
+ RequestId: this.requestId,
1202
+ ChatId: this.chatToken.chatId
1203
+ });
1204
+ return [2 /*return*/, error_14];
1205
+ case 12: return [2 /*return*/];
1206
+ }
1207
+ });
1208
+ });
1209
+ };
1210
+ OmnichannelChatSDK.prototype.onTypingEvent = function (onTypingEventCallback) {
1211
+ var _a;
1212
+ return __awaiter(this, void 0, void 0, function () {
1213
+ return __generator(this, function (_b) {
1214
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnTypingEvent, {
1215
+ RequestId: this.requestId,
1216
+ ChatId: this.chatToken.chatId
856
1217
  });
1218
+ if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
1219
+ try {
1220
+ this.conversation.onTypingEvent(onTypingEventCallback);
1221
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnTypingEvent, {
1222
+ RequestId: this.requestId,
1223
+ ChatId: this.chatToken.chatId
1224
+ });
1225
+ }
1226
+ catch (_c) {
1227
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnTypingEvent, {
1228
+ RequestId: this.requestId,
1229
+ ChatId: this.chatToken.chatId
1230
+ });
1231
+ }
1232
+ }
1233
+ else {
1234
+ try {
1235
+ (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) {
1236
+ var messageType = message.messageType;
1237
+ // Filter out customer messages
1238
+ if (utilities_1.isCustomerMessage(message)) {
1239
+ return;
1240
+ }
1241
+ if (messageType === MessageType_1.default.Typing) {
1242
+ onTypingEventCallback(message);
1243
+ }
1244
+ });
1245
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnTypingEvent, {
1246
+ RequestId: this.requestId,
1247
+ ChatId: this.chatToken.chatId
1248
+ });
1249
+ }
1250
+ catch (_d) {
1251
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnTypingEvent, {
1252
+ RequestId: this.requestId,
1253
+ ChatId: this.chatToken.chatId
1254
+ });
1255
+ }
1256
+ }
857
1257
  return [2 /*return*/];
858
1258
  });
859
1259
  });
@@ -867,53 +1267,130 @@ var OmnichannelChatSDK = /** @class */ (function () {
867
1267
  RequestId: this.requestId,
868
1268
  ChatId: this.chatToken.chatId
869
1269
  });
870
- try {
871
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) {
872
- var members = message.members;
873
- // Agent ending conversation would have 1 member left in the chat thread
874
- if (members.length === 1) {
875
- onAgentEndSessionCallback(message);
876
- if (_this.refreshTokenTimer !== null) {
877
- clearInterval(_this.refreshTokenTimer);
878
- _this.refreshTokenTimer = null;
879
- }
880
- }
881
- });
882
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
883
- RequestId: this.requestId,
884
- ChatId: this.chatToken.chatId
885
- });
1270
+ if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
1271
+ try {
1272
+ this.conversation.registerOnThreadUpdate(function (event) {
1273
+ onAgentEndSessionCallback(event);
1274
+ });
1275
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1276
+ RequestId: this.requestId,
1277
+ ChatId: this.chatToken.chatId
1278
+ });
1279
+ }
1280
+ catch (error) {
1281
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1282
+ RequestId: this.requestId,
1283
+ ChatId: this.chatToken.chatId
1284
+ });
1285
+ }
886
1286
  }
887
- catch (error) {
888
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
889
- RequestId: this.requestId,
890
- ChatId: this.chatToken.chatId
891
- });
1287
+ else {
1288
+ try {
1289
+ (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) {
1290
+ var members = message.members;
1291
+ // Agent ending conversation would have 1 member left in the chat thread
1292
+ if (members.length === 1) {
1293
+ onAgentEndSessionCallback(message);
1294
+ if (_this.refreshTokenTimer !== null) {
1295
+ clearInterval(_this.refreshTokenTimer);
1296
+ _this.refreshTokenTimer = null;
1297
+ }
1298
+ }
1299
+ });
1300
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1301
+ RequestId: this.requestId,
1302
+ ChatId: this.chatToken.chatId
1303
+ });
1304
+ }
1305
+ catch (error) {
1306
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1307
+ RequestId: this.requestId,
1308
+ ChatId: this.chatToken.chatId
1309
+ });
1310
+ }
892
1311
  }
893
1312
  return [2 /*return*/];
894
1313
  });
895
1314
  });
896
1315
  };
897
1316
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
1317
+ var _a, _b, _c, _d;
898
1318
  return __awaiter(this, void 0, void 0, function () {
899
- var fileMetadata, messageToSend, error_10;
900
- return __generator(this, function (_a) {
901
- switch (_a.label) {
1319
+ var createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_15, fileMetadata, messageToSend, error_16;
1320
+ return __generator(this, function (_e) {
1321
+ switch (_e.label) {
902
1322
  case 0:
903
1323
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.UploadFileAttachment, {
904
1324
  RequestId: this.requestId,
905
1325
  ChatId: this.chatToken.chatId
906
1326
  });
907
- if (!(platform_1.default.isReactNative() || platform_1.default.isNode())) return [3 /*break*/, 2];
908
- return [4 /*yield*/, this.conversation.sendFileData(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
1327
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 7];
1328
+ return [4 /*yield*/, ((_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.createObject((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId, fileInfo))];
909
1329
  case 1:
910
- fileMetadata = _a.sent();
911
- return [3 /*break*/, 4];
912
- case 2: return [4 /*yield*/, this.conversation.uploadFile(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
1330
+ createObjectResponse = _e.sent();
1331
+ documentId = createObjectResponse.id;
1332
+ return [4 /*yield*/, ((_c = this.AMSClient) === null || _c === void 0 ? void 0 : _c.uploadDocument(documentId, fileInfo))];
1333
+ case 2:
1334
+ uploadDocumentResponse = _e.sent();
1335
+ fileIdsProperty = {
1336
+ amsReferences: JSON.stringify([documentId])
1337
+ };
1338
+ fileMetaProperty = {
1339
+ amsMetadata: JSON.stringify([{
1340
+ contentType: fileInfo.type,
1341
+ fileName: fileInfo.name
1342
+ }])
1343
+ };
1344
+ sendMessageRequest = {
1345
+ content: '',
1346
+ metadata: __assign(__assign({ widgetId: this.omnichannelConfig.widgetId, clientMessageId: Date.now().toString() }, fileIdsProperty), fileMetaProperty)
1347
+ };
1348
+ messageToSend = {
1349
+ content: "",
1350
+ timestamp: new Date(),
1351
+ contentType: MessageContentType_1.default.Text,
1352
+ deliveryMode: DeliveryMode_1.default.Bridged,
1353
+ messageType: MessageType_1.default.UserMessage,
1354
+ tags: __spreadArrays(MessageTags_1.defaultMessageTags),
1355
+ sender: {
1356
+ displayName: "Customer",
1357
+ id: "customer",
1358
+ type: PersonType_1.default.User,
1359
+ },
1360
+ fileMetadata: uploadDocumentResponse
1361
+ };
1362
+ _e.label = 3;
913
1363
  case 3:
914
- fileMetadata = _a.sent();
915
- _a.label = 4;
1364
+ _e.trys.push([3, 5, , 6]);
1365
+ return [4 /*yield*/, ((_d = this.conversation) === null || _d === void 0 ? void 0 : _d.sendMessage(sendMessageRequest))];
916
1366
  case 4:
1367
+ _e.sent();
1368
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UploadFileAttachment, {
1369
+ RequestId: this.requestId,
1370
+ ChatId: this.chatToken.chatId
1371
+ });
1372
+ return [2 /*return*/, messageToSend];
1373
+ case 5:
1374
+ error_15 = _e.sent();
1375
+ console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
1376
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
1377
+ RequestId: this.requestId,
1378
+ ChatId: this.chatToken.chatId
1379
+ });
1380
+ return [3 /*break*/, 6];
1381
+ case 6: return [2 /*return*/, {}];
1382
+ case 7:
1383
+ fileMetadata = void 0;
1384
+ if (!(platform_1.default.isReactNative() || platform_1.default.isNode())) return [3 /*break*/, 9];
1385
+ return [4 /*yield*/, this.conversation.sendFileData(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
1386
+ case 8:
1387
+ fileMetadata = _e.sent();
1388
+ return [3 /*break*/, 11];
1389
+ case 9: return [4 /*yield*/, this.conversation.uploadFile(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
1390
+ case 10:
1391
+ fileMetadata = _e.sent();
1392
+ _e.label = 11;
1393
+ case 11:
917
1394
  messageToSend = {
918
1395
  content: "",
919
1396
  timestamp: new Date(),
@@ -928,60 +1405,84 @@ var OmnichannelChatSDK = /** @class */ (function () {
928
1405
  },
929
1406
  fileMetadata: fileMetadata
930
1407
  };
931
- _a.label = 5;
932
- case 5:
933
- _a.trys.push([5, 7, , 8]);
1408
+ _e.label = 12;
1409
+ case 12:
1410
+ _e.trys.push([12, 14, , 15]);
934
1411
  return [4 /*yield*/, this.conversation.sendFileMessage(fileMetadata, messageToSend)];
935
- case 6:
936
- _a.sent();
1412
+ case 13:
1413
+ _e.sent();
937
1414
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UploadFileAttachment, {
938
1415
  RequestId: this.requestId,
939
1416
  ChatId: this.chatToken.chatId
940
1417
  });
941
1418
  return [2 /*return*/, messageToSend];
942
- case 7:
943
- error_10 = _a.sent();
944
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_10);
1419
+ case 14:
1420
+ error_16 = _e.sent();
1421
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_16);
945
1422
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
946
1423
  RequestId: this.requestId,
947
1424
  ChatId: this.chatToken.chatId
948
1425
  });
949
- return [2 /*return*/, error_10];
950
- case 8: return [2 /*return*/];
1426
+ return [2 /*return*/, error_16];
1427
+ case 15: return [2 /*return*/];
951
1428
  }
952
1429
  });
953
1430
  });
954
1431
  };
955
1432
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
1433
+ var _a, _b;
956
1434
  return __awaiter(this, void 0, void 0, function () {
957
- var downloadedFile, error_11;
958
- return __generator(this, function (_a) {
959
- switch (_a.label) {
1435
+ var response, view_location, viewResponse, _c, downloadedFile, error_17;
1436
+ return __generator(this, function (_d) {
1437
+ switch (_d.label) {
960
1438
  case 0:
961
1439
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
962
1440
  RequestId: this.requestId,
963
1441
  ChatId: this.chatToken.chatId
964
1442
  });
965
- _a.label = 1;
1443
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 6];
1444
+ _d.label = 1;
966
1445
  case 1:
967
- _a.trys.push([1, 3, , 4]);
968
- return [4 /*yield*/, this.conversation.downloadFile(fileMetadata)];
1446
+ _d.trys.push([1, 4, , 5]);
1447
+ return [4 /*yield*/, ((_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.getViewStatus(fileMetadata))];
969
1448
  case 2:
970
- downloadedFile = _a.sent();
1449
+ response = _d.sent();
1450
+ view_location = response.view_location;
1451
+ return [4 /*yield*/, ((_b = this.AMSClient) === null || _b === void 0 ? void 0 : _b.getView(fileMetadata, view_location))];
1452
+ case 3:
1453
+ viewResponse = _d.sent();
1454
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
1455
+ RequestId: this.requestId,
1456
+ ChatId: this.chatToken.chatId
1457
+ });
1458
+ return [2 /*return*/, viewResponse];
1459
+ case 4:
1460
+ _c = _d.sent();
1461
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
1462
+ RequestId: this.requestId,
1463
+ ChatId: this.chatToken.chatId
1464
+ });
1465
+ throw new Error('DownloadFileAttachmentFailed');
1466
+ case 5: return [3 /*break*/, 9];
1467
+ case 6:
1468
+ _d.trys.push([6, 8, , 9]);
1469
+ return [4 /*yield*/, this.conversation.downloadFile(fileMetadata)];
1470
+ case 7:
1471
+ downloadedFile = _d.sent();
971
1472
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
972
1473
  RequestId: this.requestId,
973
1474
  ChatId: this.chatToken.chatId
974
1475
  });
975
1476
  return [2 /*return*/, downloadedFile];
976
- case 3:
977
- error_11 = _a.sent();
978
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_11);
1477
+ case 8:
1478
+ error_17 = _d.sent();
1479
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_17);
979
1480
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
980
1481
  RequestId: this.requestId,
981
1482
  ChatId: this.chatToken.chatId
982
1483
  });
983
1484
  throw new Error('DownloadFileAttachmentFailed');
984
- case 4: return [2 /*return*/];
1485
+ case 9: return [2 /*return*/];
985
1486
  }
986
1487
  });
987
1488
  });
@@ -1003,7 +1504,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1003
1504
  ChatId: this.chatToken.chatId,
1004
1505
  EmailAddress: body.emailAddress,
1005
1506
  DefaultAttachmentMessage: body.attachmentMessage,
1006
- CustomerLocale: body.locale
1507
+ CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
1007
1508
  };
1008
1509
  emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
1009
1510
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
@@ -1053,71 +1554,130 @@ var OmnichannelChatSDK = /** @class */ (function () {
1053
1554
  });
1054
1555
  });
1055
1556
  };
1056
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1057
- if (protocol === void 0) { protocol = ChatAdapterProtocols_1.default.IC3; }
1557
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1558
+ if (optionalParams === void 0) { optionalParams = {}; }
1058
1559
  return __awaiter(this, void 0, void 0, function () {
1560
+ var protocol, supportedChatAdapterProtocols;
1059
1561
  var _this = this;
1060
1562
  return __generator(this, function (_a) {
1061
1563
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1062
1564
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1063
1565
  }
1064
- if (protocol !== ChatAdapterProtocols_1.default.IC3) {
1566
+ protocol = optionalParams.protocol;
1567
+ supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1568
+ if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1065
1569
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1066
1570
  }
1067
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1068
- var ic3AdapterCDNUrl;
1069
- var _this = this;
1070
- var _a;
1071
- return __generator(this, function (_b) {
1072
- switch (_b.label) {
1073
- case 0:
1074
- ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol);
1075
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1076
- IC3Adapter: ic3AdapterCDNUrl
1077
- });
1078
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1079
- return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1080
- /* istanbul ignore next */
1081
- _this.debug && console.debug('IC3Adapter loaded!');
1082
- var adapterConfig = {
1083
- chatToken: _this.chatToken,
1084
- userDisplayName: 'Customer',
1085
- userId: 'teamsvisitor',
1086
- sdkURL: _this.resolveIC3ClientUrl(),
1087
- sdk: _this.IC3Client
1088
- };
1089
- var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1090
- adapter.logger = _this.ic3ClientLogger;
1091
- // Keep iframe communication alive to reuse the same IC3Client instance
1092
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1093
- _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1094
- resolve(adapter);
1095
- }, function () {
1096
- _this.scenarioMarker.failScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1097
- reject('Failed to load IC3Adapter');
1098
- })];
1099
- case 1:
1100
- _b.sent();
1101
- return [2 /*return*/];
1102
- }
1103
- });
1104
- }); })];
1571
+ if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1572
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1573
+ var options, defaultEgressMiddlewares, defaultIngressMiddlewares, egressMiddleware, ingressMiddleware, featuresOption, acsAdapterCDNUrl;
1574
+ var _this = this;
1575
+ var _a;
1576
+ return __generator(this, function (_b) {
1577
+ switch (_b.label) {
1578
+ case 0:
1579
+ options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1580
+ defaultEgressMiddlewares = [createChannelDataEgressMiddleware_1.default({ widgetId: this.omnichannelConfig.widgetId }), createFormatEgressTagsMiddleware_1.default()];
1581
+ defaultIngressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1582
+ egressMiddleware = (options === null || options === void 0 ? void 0 : options.egressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultEgressMiddlewares) : __spreadArrays(defaultEgressMiddlewares);
1583
+ ingressMiddleware = (options === null || options === void 0 ? void 0 : options.ingressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultIngressMiddlewares) : __spreadArrays(defaultIngressMiddlewares);
1584
+ featuresOption = __assign(__assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false }, options), { // overrides
1585
+ ingressMiddleware: ingressMiddleware,
1586
+ egressMiddleware: egressMiddleware });
1587
+ acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1588
+ (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1589
+ ACSAdapter: acsAdapterCDNUrl
1590
+ });
1591
+ return [4 /*yield*/, WebUtils_1.loadScript(acsAdapterCDNUrl, function () {
1592
+ /* istanbul ignore next */
1593
+ _this.debug && console.debug('ACSAdapter loaded!');
1594
+ try {
1595
+ var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1596
+ var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1597
+ var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, // chatClient
1598
+ undefined, // logger
1599
+ featuresOption);
1600
+ resolve(adapter);
1601
+ }
1602
+ catch (_a) {
1603
+ throw new Error('Failed to load ACSAdapter');
1604
+ }
1605
+ }, function () {
1606
+ reject('Failed to load ACSADapter');
1607
+ })];
1608
+ case 1:
1609
+ _b.sent();
1610
+ return [2 /*return*/];
1611
+ }
1612
+ });
1613
+ }); })];
1614
+ }
1615
+ else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1616
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1617
+ var options, ic3AdapterCDNUrl;
1618
+ var _this = this;
1619
+ var _a;
1620
+ return __generator(this, function (_b) {
1621
+ switch (_b.label) {
1622
+ case 0:
1623
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1624
+ ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1625
+ (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1626
+ IC3Adapter: ic3AdapterCDNUrl
1627
+ });
1628
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1629
+ return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1630
+ /* istanbul ignore next */
1631
+ _this.debug && console.debug('IC3Adapter loaded!');
1632
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1633
+ );
1634
+ var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1635
+ adapter.logger = _this.ic3ClientLogger;
1636
+ _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1637
+ resolve(adapter);
1638
+ }, function () {
1639
+ _this.scenarioMarker.failScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1640
+ reject('Failed to load IC3Adapter');
1641
+ })];
1642
+ case 1:
1643
+ _b.sent();
1644
+ return [2 /*return*/];
1645
+ }
1646
+ });
1647
+ }); })];
1648
+ }
1649
+ return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1105
1650
  });
1106
1651
  });
1107
1652
  };
1108
1653
  OmnichannelChatSDK.prototype.getVoiceVideoCalling = function (params) {
1109
1654
  if (params === void 0) { params = {}; }
1110
1655
  return __awaiter(this, void 0, void 0, function () {
1111
- var chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1656
+ var exceptionDetails, exceptionDetails, chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1112
1657
  var _this = this;
1113
1658
  return __generator(this, function (_a) {
1114
1659
  switch (_a.label) {
1115
1660
  case 0:
1661
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1116
1662
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1117
- return [2 /*return*/, Promise.reject('VoiceVideoCalling is only supported on browser')];
1663
+ exceptionDetails = {
1664
+ response: "UnsupportedPlatform",
1665
+ message: "VoiceVideoCalling is only supported on browser"
1666
+ };
1667
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1668
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1669
+ });
1670
+ throw new Error(exceptionDetails.response);
1118
1671
  }
1119
1672
  if (this.callingOption.toString() === CallingOptionsOptionSetNumber_1.default.NoCalling.toString()) {
1120
- return [2 /*return*/, Promise.reject('Voice and video call is not enabled')];
1673
+ exceptionDetails = {
1674
+ response: "FeatureDisabled",
1675
+ message: "Voice and video call is not enabled"
1676
+ };
1677
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1678
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1679
+ });
1680
+ throw new Error(exceptionDetails.response);
1121
1681
  }
1122
1682
  return [4 /*yield*/, this.getChatConfig()];
1123
1683
  case 1:
@@ -1127,25 +1687,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
1127
1687
  widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\"");
1128
1688
  result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
1129
1689
  if (result && result.length) {
1130
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1131
- var LiveChatWidgetLibCDNUrl;
1690
+ return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
1691
+ var LiveChatWidgetLibCDNUrl, defaultParams;
1132
1692
  var _this = this;
1133
1693
  var _a;
1134
1694
  return __generator(this, function (_b) {
1135
1695
  switch (_b.label) {
1136
1696
  case 0:
1137
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1138
1697
  LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/CallingBundle.js";
1139
1698
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1140
1699
  VoiceVideoCalling: LiveChatWidgetLibCDNUrl
1141
1700
  });
1701
+ defaultParams = {
1702
+ logger: this.callingSdkLogger
1703
+ };
1142
1704
  return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
1143
1705
  var VoiceVideoCalling;
1144
1706
  return __generator(this, function (_a) {
1145
1707
  switch (_a.label) {
1146
1708
  case 0:
1147
1709
  this.debug && console.debug(LiveChatWidgetLibCDNUrl + " loaded!");
1148
- return [4 /*yield*/, createVoiceVideoCalling_1.default(params)];
1710
+ return [4 /*yield*/, createVoiceVideoCalling_1.default(__assign(__assign({}, params), defaultParams))];
1149
1711
  case 1:
1150
1712
  VoiceVideoCalling = _a.sent();
1151
1713
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
@@ -1158,13 +1720,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1158
1720
  var exceptionDetails;
1159
1721
  return __generator(this, function (_a) {
1160
1722
  exceptionDetails = {
1161
- response: "VoiceVideoCallingLoadFailed"
1723
+ response: "VoiceVideoCallingLoadFailed",
1724
+ message: "Failed to load VoiceVideoCalling"
1162
1725
  };
1163
1726
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1164
1727
  ExceptionDetails: JSON.stringify(exceptionDetails)
1165
1728
  });
1166
- reject('Failed to load VoiceVideoCalling');
1167
- return [2 /*return*/];
1729
+ throw new Error(exceptionDetails.response);
1168
1730
  });
1169
1731
  }); })];
1170
1732
  case 1:
@@ -1179,6 +1741,96 @@ var OmnichannelChatSDK = /** @class */ (function () {
1179
1741
  });
1180
1742
  });
1181
1743
  };
1744
+ OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1745
+ return __awaiter(this, void 0, void 0, function () {
1746
+ var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, liveWorkItemDetails, participantJoined, participantType, surveyInviteLinkRequest, optionalParams, ownerId, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1747
+ return __generator(this, function (_a) {
1748
+ switch (_a.label) {
1749
+ case 0:
1750
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1751
+ RequestId: this.requestId
1752
+ });
1753
+ _a.label = 1;
1754
+ case 1:
1755
+ _a.trys.push([1, 6, , 7]);
1756
+ chatConfig = this.liveChatConfig;
1757
+ liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
1758
+ msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId, postConversationBotSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationBotSurveyOwnerId;
1759
+ if (!(msdyn_postconversationsurveyenable === "true")) return [3 /*break*/, 4];
1760
+ return [4 /*yield*/, this.getConversationDetails()];
1761
+ case 2:
1762
+ liveWorkItemDetails = _a.sent();
1763
+ participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.canRenderPostChat) === "True";
1764
+ participantType = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.participantType;
1765
+ conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.conversationId;
1766
+ surveyInviteLinkRequest = {
1767
+ "FormId": participantType === "Bot" ? msfp_botsourcesurveyidentifier : msfp_sourcesurveyidentifier,
1768
+ "ConversationId": conversationId,
1769
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId)
1770
+ };
1771
+ optionalParams = {
1772
+ "requestId": this.requestId
1773
+ };
1774
+ if (this.authenticatedUserToken) {
1775
+ optionalParams.authenticatedUserToken = this.authenticatedUserToken;
1776
+ }
1777
+ ownerId = participantType === "Bot" ? postConversationBotSurveyOwnerId : postConversationSurveyOwnerId;
1778
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(ownerId, surveyInviteLinkRequest, optionalParams)];
1779
+ case 3:
1780
+ surveyInviteLinkResponse = _a.sent();
1781
+ surveyInviteLink = void 0, formsProLocale = void 0;
1782
+ if (surveyInviteLinkResponse != null) {
1783
+ if (surveyInviteLinkResponse.inviteList != null && surveyInviteLinkResponse.inviteList.length == 1) {
1784
+ surveyInviteLink = surveyInviteLinkResponse.inviteList[0].invitationLink;
1785
+ }
1786
+ else {
1787
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1788
+ ConversationId: conversationId,
1789
+ RequestId: this.requestId,
1790
+ ExceptionDetails: "Survey Invite link failed to send response."
1791
+ });
1792
+ return [2 /*return*/, Promise.reject("Survey Invite link failed to send response.")];
1793
+ }
1794
+ if (surveyInviteLinkResponse.formsProLocaleCode != null) {
1795
+ formsProLocale = surveyInviteLinkResponse.formsProLocaleCode;
1796
+ }
1797
+ postChatContext = {
1798
+ participantJoined: participantJoined,
1799
+ participantType: participantType,
1800
+ surveyInviteLink: surveyInviteLink,
1801
+ formsProLocale: formsProLocale
1802
+ };
1803
+ return [2 /*return*/, Promise.resolve(postChatContext)];
1804
+ }
1805
+ else {
1806
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1807
+ ConversationId: conversationId,
1808
+ RequestId: this.requestId,
1809
+ ExceptionDetails: "surveyInviteLinkResponse is null."
1810
+ });
1811
+ return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
1812
+ }
1813
+ return [3 /*break*/, 5];
1814
+ case 4:
1815
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1816
+ RequestId: this.requestId,
1817
+ ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
1818
+ });
1819
+ return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side.")];
1820
+ case 5: return [3 /*break*/, 7];
1821
+ case 6:
1822
+ ex_1 = _a.sent();
1823
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1824
+ ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
1825
+ RequestId: this.requestId,
1826
+ ExceptionDetails: JSON.stringify(ex_1)
1827
+ });
1828
+ return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
1829
+ case 7: return [2 /*return*/];
1830
+ }
1831
+ });
1832
+ });
1833
+ };
1182
1834
  OmnichannelChatSDK.prototype.getIC3Client = function () {
1183
1835
  return __awaiter(this, void 0, void 0, function () {
1184
1836
  var IC3Client;
@@ -1205,7 +1857,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1205
1857
  this.debug && console.debug('IC3Client');
1206
1858
  // Use IC3Client if browser is detected
1207
1859
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1208
- var ic3ClientCDNUrl;
1860
+ var ic3ClientCDNUrl, IC3Client;
1209
1861
  var _this = this;
1210
1862
  var _a;
1211
1863
  return __generator(this, function (_b) {
@@ -1216,6 +1868,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1216
1868
  IC3Client: ic3ClientCDNUrl
1217
1869
  });
1218
1870
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
1871
+ if (!this.IC3SDKProvider) return [3 /*break*/, 2];
1872
+ return [4 /*yield*/, this.IC3SDKProvider.getSDK({
1873
+ hostType: HostType_1.default.IFrame,
1874
+ protocolType: ProtocoleType_1.default.IC3V1SDK,
1875
+ logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
1876
+ })];
1877
+ case 1:
1878
+ IC3Client = _b.sent();
1879
+ return [2 /*return*/, resolve(IC3Client)];
1880
+ case 2:
1219
1881
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1220
1882
  var ic3sdk, IC3SDKProvider, IC3Client;
1221
1883
  return __generator(this, function (_a) {
@@ -1252,7 +1914,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1252
1914
  });
1253
1915
  reject('Failed to load IC3Client');
1254
1916
  })];
1255
- case 1:
1917
+ case 3:
1256
1918
  _b.sent();
1257
1919
  return [2 /*return*/];
1258
1920
  }
@@ -1264,15 +1926,20 @@ var OmnichannelChatSDK = /** @class */ (function () {
1264
1926
  };
1265
1927
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1266
1928
  return __awaiter(this, void 0, void 0, function () {
1267
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, exceptionDetails, _a, exceptionDetails, exceptionDetails, error_12;
1268
- return __generator(this, function (_b) {
1269
- switch (_b.label) {
1929
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1930
+ return __generator(this, function (_a) {
1931
+ switch (_a.label) {
1270
1932
  case 0:
1271
- _b.trys.push([0, 8, , 9]);
1933
+ _a.trys.push([0, 4, , 5]);
1272
1934
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1273
1935
  case 1:
1274
- liveChatConfig = _b.sent();
1275
- dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin;
1936
+ liveChatConfig = _a.sent();
1937
+ dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1938
+ msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1939
+ this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
1940
+ this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1941
+ /* istanbul ignore next */
1942
+ this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
1276
1943
  setting = dataMaskingConfig.setting;
1277
1944
  if (setting.msdyn_maskforcustomer) {
1278
1945
  this.dataMaskingRules = dataMaskingConfig.dataMaskingRules;
@@ -1292,47 +1959,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1292
1959
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1293
1960
  this.preChatSurvey = preChatSurvey;
1294
1961
  }
1295
- if (!this.authSettings) return [3 /*break*/, 7];
1296
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1297
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1298
- _b.label = 2;
1962
+ if (!this.authSettings) return [3 /*break*/, 3];
1963
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1299
1964
  case 2:
1300
- _b.trys.push([2, 4, , 5]);
1301
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1965
+ _a.sent();
1966
+ _a.label = 3;
1302
1967
  case 3:
1303
- token = _b.sent();
1304
- if (token) {
1305
- this.authenticatedUserToken = token;
1306
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1307
- }
1308
- else {
1309
- exceptionDetails = {
1310
- response: "UndefinedAuthToken"
1311
- };
1312
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1313
- ExceptionDetails: JSON.stringify(exceptionDetails)
1314
- });
1315
- }
1316
- return [3 /*break*/, 5];
1317
- case 4:
1318
- _a = _b.sent();
1319
- exceptionDetails = {
1320
- response: "GetAuthTokenFailed"
1321
- };
1322
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1323
- ExceptionDetails: JSON.stringify(exceptionDetails)
1324
- });
1325
- return [3 /*break*/, 5];
1326
- case 5: return [3 /*break*/, 7];
1327
- case 6:
1328
- exceptionDetails = {
1329
- response: "GetAuthTokenNotFound"
1330
- };
1331
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1332
- ExceptionDetails: JSON.stringify(exceptionDetails)
1333
- });
1334
- _b.label = 7;
1335
- case 7:
1336
1968
  if (this.preChatSurvey) {
1337
1969
  /* istanbul ignore next */
1338
1970
  this.debug && console.log('Prechat Survey!');
@@ -1340,11 +1972,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1340
1972
  this.callingOption = msdyn_callingoptions;
1341
1973
  this.liveChatConfig = liveChatConfig;
1342
1974
  return [2 /*return*/, this.liveChatConfig];
1343
- case 8:
1344
- error_12 = _b.sent();
1345
- console.error("OmnichannelChatSDK/getChatConfig/error " + error_12);
1346
- return [2 /*return*/, error_12];
1347
- case 9: return [2 /*return*/];
1975
+ case 4:
1976
+ error_18 = _a.sent();
1977
+ console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1978
+ return [2 /*return*/, error_18];
1979
+ case 5: return [2 /*return*/];
1348
1980
  }
1349
1981
  });
1350
1982
  });
@@ -1359,20 +1991,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
1359
1991
  return libraries_1.default.getIC3ClientCDNUrl();
1360
1992
  };
1361
1993
  OmnichannelChatSDK.prototype.resolveChatAdapterUrl = function (protocol) {
1362
- if (protocol !== ChatAdapterProtocols_1.default.IC3) {
1994
+ var supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1995
+ if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1363
1996
  throw new Error("ChatAdapter for protocol " + protocol + " currently not supported");
1364
1997
  }
1365
- if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
1366
- return this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterCDNUrl;
1998
+ if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1999
+ if (this.chatSDKConfig.chatAdapterConfig && 'webChatACSAdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
2000
+ return this.chatSDKConfig.chatAdapterConfig.webChatACSAdapterCDNUrl;
2001
+ }
2002
+ if (this.chatSDKConfig.chatAdapterConfig && 'webChatACSAdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
2003
+ return libraries_1.default.getACSAdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatACSAdapterVersion);
2004
+ }
2005
+ return libraries_1.default.getACSAdapterCDNUrl();
1367
2006
  }
1368
- if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
1369
- return libraries_1.default.getIC3AdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterVersion);
2007
+ else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
2008
+ if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
2009
+ return this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterCDNUrl;
2010
+ }
2011
+ if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
2012
+ return libraries_1.default.getIC3AdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterVersion);
2013
+ }
2014
+ return libraries_1.default.getIC3AdapterCDNUrl();
1370
2015
  }
1371
- return libraries_1.default.getIC3AdapterCDNUrl();
2016
+ return '';
1372
2017
  };
1373
2018
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
1374
2019
  return __awaiter(this, void 0, void 0, function () {
1375
- var sessionInfo, error_13, exceptionDetails;
2020
+ var sessionInfo, error_19, exceptionDetails;
1376
2021
  return __generator(this, function (_a) {
1377
2022
  switch (_a.label) {
1378
2023
  case 0:
@@ -1397,7 +2042,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1397
2042
  });
1398
2043
  return [3 /*break*/, 4];
1399
2044
  case 3:
1400
- error_13 = _a.sent();
2045
+ error_19 = _a.sent();
1401
2046
  exceptionDetails = {
1402
2047
  response: "UpdateChatTokenFailed"
1403
2048
  };
@@ -1406,13 +2051,64 @@ var OmnichannelChatSDK = /** @class */ (function () {
1406
2051
  ChatId: this.chatToken.chatId,
1407
2052
  ExceptionDetails: JSON.stringify(exceptionDetails)
1408
2053
  });
1409
- console.error("OmnichannelChatSDK/updateChatToken/error " + error_13);
2054
+ console.error("OmnichannelChatSDK/updateChatToken/error " + error_19);
1410
2055
  return [3 /*break*/, 4];
1411
2056
  case 4: return [2 /*return*/];
1412
2057
  }
1413
2058
  });
1414
2059
  });
1415
2060
  };
2061
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2062
+ return __awaiter(this, void 0, void 0, function () {
2063
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2064
+ return __generator(this, function (_b) {
2065
+ switch (_b.label) {
2066
+ case 0:
2067
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2068
+ this.chatSDKConfig.getAuthToken = provider;
2069
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2070
+ _b.label = 1;
2071
+ case 1:
2072
+ _b.trys.push([1, 3, , 4]);
2073
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2074
+ case 2:
2075
+ token = _b.sent();
2076
+ if (token) {
2077
+ this.authenticatedUserToken = token;
2078
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2079
+ }
2080
+ else {
2081
+ exceptionDetails = {
2082
+ response: "UndefinedAuthToken"
2083
+ };
2084
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2085
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2086
+ });
2087
+ }
2088
+ return [3 /*break*/, 4];
2089
+ case 3:
2090
+ _a = _b.sent();
2091
+ exceptionDetails = {
2092
+ response: "GetAuthTokenFailed"
2093
+ };
2094
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2095
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2096
+ });
2097
+ return [3 /*break*/, 4];
2098
+ case 4: return [3 /*break*/, 6];
2099
+ case 5:
2100
+ exceptionDetails = {
2101
+ response: "GetAuthTokenNotFound"
2102
+ };
2103
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2104
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2105
+ });
2106
+ _b.label = 6;
2107
+ case 6: return [2 /*return*/];
2108
+ }
2109
+ });
2110
+ });
2111
+ };
1416
2112
  return OmnichannelChatSDK;
1417
2113
  }());
1418
2114
  exports.default = OmnichannelChatSDK;