@microsoft/omnichannel-chat-widget 1.0.6-main.ffb4e2a → 1.1.1-main.1f4a6a7
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.
- package/lib/cjs/common/Constants.js +2 -0
- package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +20 -15
- package/lib/cjs/common/telemetry/TelemetryConstants.js +2 -0
- package/lib/cjs/common/telemetry/TelemetryHelper.js +25 -15
- package/lib/cjs/common/utils.js +17 -2
- package/lib/cjs/components/draggable/DraggableChatWidget.js +168 -0
- package/lib/cjs/components/draggable/DraggableEventEmitter.js +74 -0
- package/lib/cjs/components/draggable/DraggableEventNames.js +14 -0
- package/lib/cjs/components/draggable/DraggableEventReceiver.js +34 -0
- package/lib/cjs/components/draggable/IDraggableElementPosition.js +1 -0
- package/lib/cjs/components/draggable/IDraggableElementPositionDelta.js +1 -0
- package/lib/cjs/components/draggable/IDraggableEvent.js +1 -0
- package/lib/cjs/components/footerstateful/FooterStateful.js +2 -2
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +21 -12
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/interfaces/IWebChatTranscriptConfig.js +1 -0
- package/lib/cjs/components/headerstateful/HeaderStateful.js +27 -0
- package/lib/cjs/components/livechatwidget/common/createDownloadTranscriptProps.js +27 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +13 -2
- package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +15 -5
- package/lib/cjs/components/livechatwidget/common/startChat.js +1 -1
- package/lib/cjs/components/livechatwidget/interfaces/IDraggableChatWidgetProps.js +1 -0
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +58 -30
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +6 -0
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +48 -13
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +5 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSentMessageAnchorStyles.js +10 -0
- package/lib/cjs/plugins/createChatTranscript.js +548 -0
- package/lib/esm/common/Constants.js +2 -0
- package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +18 -14
- package/lib/esm/common/telemetry/TelemetryConstants.js +2 -0
- package/lib/esm/common/telemetry/TelemetryHelper.js +25 -15
- package/lib/esm/common/utils.js +15 -1
- package/lib/esm/components/draggable/DraggableChatWidget.js +158 -0
- package/lib/esm/components/draggable/DraggableEventEmitter.js +64 -0
- package/lib/esm/components/draggable/DraggableEventNames.js +7 -0
- package/lib/esm/components/draggable/DraggableEventReceiver.js +25 -0
- package/lib/esm/components/draggable/IDraggableElementPosition.js +1 -0
- package/lib/esm/components/draggable/IDraggableElementPositionDelta.js +1 -0
- package/lib/esm/components/draggable/IDraggableEvent.js +1 -0
- package/lib/esm/components/footerstateful/FooterStateful.js +2 -2
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +22 -13
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/interfaces/IWebChatTranscriptConfig.js +1 -0
- package/lib/esm/components/headerstateful/HeaderStateful.js +27 -0
- package/lib/esm/components/livechatwidget/common/createDownloadTranscriptProps.js +20 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +13 -2
- package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +15 -5
- package/lib/esm/components/livechatwidget/common/startChat.js +1 -1
- package/lib/esm/components/livechatwidget/interfaces/IDraggableChatWidgetProps.js +1 -0
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +58 -30
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +6 -0
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +48 -13
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +5 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSentMessageAnchorStyles.js +3 -0
- package/lib/esm/plugins/createChatTranscript.js +543 -0
- package/lib/types/common/Constants.d.ts +2 -0
- package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +1 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -0
- package/lib/types/common/telemetry/definitions/Contracts.d.ts +1 -0
- package/lib/types/common/utils.d.ts +1 -0
- package/lib/types/components/draggable/DraggableChatWidget.d.ts +9 -0
- package/lib/types/components/draggable/DraggableEventEmitter.d.ts +27 -0
- package/lib/types/components/draggable/DraggableEventNames.d.ts +6 -0
- package/lib/types/components/draggable/DraggableEventReceiver.d.ts +27 -0
- package/lib/types/components/draggable/IDraggableElementPosition.d.ts +5 -0
- package/lib/types/components/draggable/IDraggableElementPositionDelta.d.ts +5 -0
- package/lib/types/components/draggable/IDraggableEvent.d.ts +12 -0
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +2 -1
- package/lib/types/components/footerstateful/downloadtranscriptstateful/interfaces/IDownloadTranscriptProps.d.ts +5 -0
- package/lib/types/components/footerstateful/downloadtranscriptstateful/interfaces/IWebChatTranscriptConfig.d.ts +13 -0
- package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +12 -0
- package/lib/types/components/livechatwidget/common/createDownloadTranscriptProps.d.ts +24 -0
- package/lib/types/components/livechatwidget/interfaces/IDraggableChatWidgetProps.d.ts +10 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/WebChatContainerStateful.d.ts +2 -2
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +5 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IRenderingMiddlewareProps.d.ts +3 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios.d.ts +2 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSentMessageAnchorStyles.d.ts +2 -0
- package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +1 -0
- package/lib/types/plugins/createChatTranscript.d.ts +2 -0
- package/package.json +4 -4
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("../common/utils");
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
|
+
class TranscriptHTMLBuilder {
|
|
12
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
13
|
+
|
|
14
|
+
constructor(options) {
|
|
15
|
+
var _this$options, _this$options2, _this$options3, _this$options4, _this$options5, _this$options6, _this$options7, _this$options8, _this$options9, _this$options10, _this$options11;
|
|
16
|
+
_defineProperty(this, "options", void 0);
|
|
17
|
+
_defineProperty(this, "pageTitle", "Customer Transcript");
|
|
18
|
+
_defineProperty(this, "attachmentMessage", "The following attachment was uploaded during the conversation: ");
|
|
19
|
+
_defineProperty(this, "networkOnlineMessage", "Connection restored. Please refresh the page");
|
|
20
|
+
_defineProperty(this, "networkOfflineMessage", "Network Error. Please make sure you are connected to the internet.");
|
|
21
|
+
_defineProperty(this, "transcriptBackgroundColor", "#FFF");
|
|
22
|
+
_defineProperty(this, "agentAvatarBackgroundColor", "#E8E8E8");
|
|
23
|
+
_defineProperty(this, "agentAvatarFontColor", "#000");
|
|
24
|
+
_defineProperty(this, "customerAvatarBackgroundColor", "#2266E3");
|
|
25
|
+
_defineProperty(this, "customerAvatarFontColor", "#FFF");
|
|
26
|
+
_defineProperty(this, "disableMarkdownMessageFormatting", false);
|
|
27
|
+
_defineProperty(this, "disableNewLineMarkdownSupport", false);
|
|
28
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
29
|
+
this.options = options;
|
|
30
|
+
if (!this.options || !this.options.messages) {
|
|
31
|
+
this.options.messages = [];
|
|
32
|
+
}
|
|
33
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.pageTitle) {
|
|
34
|
+
this.pageTitle = this.options.pageTitle;
|
|
35
|
+
}
|
|
36
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.attachmentMessage) {
|
|
37
|
+
this.attachmentMessage = this.options.attachmentMessage;
|
|
38
|
+
}
|
|
39
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.networkOnlineMessage) {
|
|
40
|
+
this.networkOnlineMessage = this.options.networkOnlineMessage;
|
|
41
|
+
}
|
|
42
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.networkOfflineMessage) {
|
|
43
|
+
this.networkOfflineMessage = this.options.networkOfflineMessage;
|
|
44
|
+
}
|
|
45
|
+
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.transcriptBackgroundColor) {
|
|
46
|
+
this.transcriptBackgroundColor = this.options.transcriptBackgroundColor;
|
|
47
|
+
}
|
|
48
|
+
if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.agentAvatarBackgroundColor) {
|
|
49
|
+
this.agentAvatarBackgroundColor = this.options.agentAvatarBackgroundColor;
|
|
50
|
+
}
|
|
51
|
+
if ((_this$options7 = this.options) !== null && _this$options7 !== void 0 && _this$options7.agentAvatarFontColor) {
|
|
52
|
+
this.agentAvatarFontColor = this.options.agentAvatarFontColor;
|
|
53
|
+
}
|
|
54
|
+
if ((_this$options8 = this.options) !== null && _this$options8 !== void 0 && _this$options8.customerAvatarBackgroundColor) {
|
|
55
|
+
this.customerAvatarBackgroundColor = this.options.customerAvatarBackgroundColor;
|
|
56
|
+
}
|
|
57
|
+
if ((_this$options9 = this.options) !== null && _this$options9 !== void 0 && _this$options9.customerAvatarFontColor) {
|
|
58
|
+
this.customerAvatarFontColor = this.options.customerAvatarFontColor;
|
|
59
|
+
}
|
|
60
|
+
if ((_this$options10 = this.options) !== null && _this$options10 !== void 0 && _this$options10.disableMarkdownMessageFormatting) {
|
|
61
|
+
this.disableMarkdownMessageFormatting = this.options.disableMarkdownMessageFormatting;
|
|
62
|
+
}
|
|
63
|
+
if ((_this$options11 = this.options) !== null && _this$options11 !== void 0 && _this$options11.disableNewLineMarkdownSupport) {
|
|
64
|
+
this.disableNewLineMarkdownSupport = this.options.disableNewLineMarkdownSupport;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
createTitleElement() {
|
|
68
|
+
const htmlData = `<title> ${this.pageTitle} </title>`;
|
|
69
|
+
return htmlData;
|
|
70
|
+
}
|
|
71
|
+
createExternalScriptElements() {
|
|
72
|
+
const htmlData = `
|
|
73
|
+
<script src="https://cdn.botframework.com/botframework-webchat/4.15.7/webchat.js"><\/script>
|
|
74
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/7.8.0/rxjs.umd.min.js" integrity="sha512-v0/YVjBcbjLN6scjmmJN+h86koeB7JhY4/2YeyA5l+rTdtKLv0VbDBNJ32rxJpsaW1QGMd1Z16lsLOSGI38Rbg==" crossorigin="anonymous" referrerpolicy="no-referrer"><\/script>
|
|
75
|
+
<script src="https://unpkg.com/react@18.2.0/umd/react.production.min.js"><\/script>
|
|
76
|
+
<script src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"><\/script>
|
|
77
|
+
<script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js" integrity="sha256-hNyljag6giCsjv/yKmxK8/VeHzvMDvc5u8AzmRvm1BI=" crossorigin="anonymous"><\/script>
|
|
78
|
+
`;
|
|
79
|
+
return htmlData;
|
|
80
|
+
}
|
|
81
|
+
createHeadElement() {
|
|
82
|
+
const htmlData = `
|
|
83
|
+
<head>
|
|
84
|
+
${this.createTitleElement()}
|
|
85
|
+
${this.createExternalScriptElements()}
|
|
86
|
+
<script>
|
|
87
|
+
function shareObservable(observable) {
|
|
88
|
+
let observers = [];
|
|
89
|
+
let subscription;
|
|
90
|
+
|
|
91
|
+
return new Observable(observer => {
|
|
92
|
+
if (!subscription) {
|
|
93
|
+
subscription = observable.subscribe({
|
|
94
|
+
complete() {
|
|
95
|
+
observers.forEach(observer => observer.complete());
|
|
96
|
+
},
|
|
97
|
+
error(err) {
|
|
98
|
+
observers.forEach(observer => observer.error(err));
|
|
99
|
+
},
|
|
100
|
+
next(value) {
|
|
101
|
+
observers.forEach(observer => observer.next(value));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
observers.push(observer);
|
|
107
|
+
|
|
108
|
+
return () => {
|
|
109
|
+
observers = observers.filter(o => o !== observer);
|
|
110
|
+
|
|
111
|
+
if (!observers.length) {
|
|
112
|
+
subscription.unsubscribe();
|
|
113
|
+
subscription = null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
<\/script>
|
|
119
|
+
<script>
|
|
120
|
+
const messages = ${JSON.stringify(this.options.messages)};
|
|
121
|
+
const disableMarkdownMessageFormatting = ${this.disableMarkdownMessageFormatting};
|
|
122
|
+
const disableNewLineMarkdownSupport = ${this.disableNewLineMarkdownSupport};
|
|
123
|
+
<\/script>
|
|
124
|
+
<script>
|
|
125
|
+
class Translator {
|
|
126
|
+
static convertTranscriptMessageToActivity(message) {
|
|
127
|
+
const {created, isControlMessage, content, tags, from, attachments, amsMetadata, amsReferences} = message;
|
|
128
|
+
const activity = {
|
|
129
|
+
from: {
|
|
130
|
+
role: 'bot'
|
|
131
|
+
},
|
|
132
|
+
type: 'message'
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Ignore control messages
|
|
136
|
+
if (isControlMessage) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (tags) {
|
|
141
|
+
const formattedTags = tags.split(',');
|
|
142
|
+
|
|
143
|
+
// Ignore system message
|
|
144
|
+
if (formattedTags.includes('system')) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Ignore hidden message
|
|
149
|
+
if (formattedTags.includes('Hidden')) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Add C1 user display name
|
|
155
|
+
if (from && from.user && from.user.displayName) {
|
|
156
|
+
activity.from.name = from.user.displayName;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Add C2 user display name
|
|
160
|
+
if (from && from.application && from.application.displayName && from.application.displayName === 'Customer') {
|
|
161
|
+
activity.from = {
|
|
162
|
+
role: 'user',
|
|
163
|
+
name: from.application.displayName
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Attachments
|
|
168
|
+
if (amsReferences && amsMetadata) {
|
|
169
|
+
const metadata = JSON.parse(amsMetadata);
|
|
170
|
+
const { fileName } = metadata[0];
|
|
171
|
+
const text = \`${this.attachmentMessage}\${fileName}\`;
|
|
172
|
+
|
|
173
|
+
if (message.attachments && message.attachments.length > 0 && message.contentUrl) {
|
|
174
|
+
activity.attachments = message.attachments;
|
|
175
|
+
activity.attachments[0].contentUrl = message.contentUrl;
|
|
176
|
+
activity.attachments[0].thumbnailUrl = message.contentUrl;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
...activity,
|
|
181
|
+
text,
|
|
182
|
+
timestamp: created
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Message
|
|
187
|
+
if (content) {
|
|
188
|
+
// Adaptive card formatting
|
|
189
|
+
if (content.includes('"text"') && content.includes('"attachments"') && content.includes('"suggestedActions"')) {
|
|
190
|
+
try {
|
|
191
|
+
const partialActivity = JSON.parse(content);
|
|
192
|
+
return {
|
|
193
|
+
...activity,
|
|
194
|
+
...partialActivity,
|
|
195
|
+
timestamp: created
|
|
196
|
+
};
|
|
197
|
+
} catch {
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
...activity,
|
|
205
|
+
text: content,
|
|
206
|
+
timestamp: created
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
<\/script>
|
|
211
|
+
<script>
|
|
212
|
+
class TranscriptAdapter {
|
|
213
|
+
constructor() {
|
|
214
|
+
this.connectionStatus$ = new window.rxjs.BehaviorSubject(0); // Uninitialized
|
|
215
|
+
this.activity$ = shareObservable(new Observable((observer) => {
|
|
216
|
+
this.activityObserver = observer;
|
|
217
|
+
|
|
218
|
+
this.connectionStatus$.next(1); // Connecting
|
|
219
|
+
this.connectionStatus$.next(2); // Online
|
|
220
|
+
|
|
221
|
+
// Retrieve messages
|
|
222
|
+
if (messages) {
|
|
223
|
+
setTimeout(() => { // setTimeout is needed due to some WebChat issues
|
|
224
|
+
messages.map((message) => {
|
|
225
|
+
this.activityObserver.next({
|
|
226
|
+
...Translator.convertTranscriptMessageToActivity(message),
|
|
227
|
+
type: 'message'
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
}, 1);
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
<\/script>
|
|
236
|
+
<style>
|
|
237
|
+
body {
|
|
238
|
+
margin: 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.message-name {
|
|
242
|
+
font-family: Segoe UI,SegoeUI,Helvetica Neue,Helvetica,Arial,sans-serif;
|
|
243
|
+
font-weight: 700;
|
|
244
|
+
font-size: 10px;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.message-timestamp {
|
|
248
|
+
font-family: Segoe UI,SegoeUI,Helvetica Neue,Helvetica,Arial,sans-serif;
|
|
249
|
+
font-weight: 500;
|
|
250
|
+
font-size: 10px;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.avatar {
|
|
254
|
+
width: 40px;
|
|
255
|
+
height: 40px;
|
|
256
|
+
border-radius: 50%;
|
|
257
|
+
text-align: center;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.avatar--bot {
|
|
261
|
+
background-color: ${this.agentAvatarBackgroundColor};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.avatar--user {
|
|
265
|
+
background-color: ${this.customerAvatarBackgroundColor};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.avatar > p {
|
|
269
|
+
font-weight: 600;
|
|
270
|
+
text-align: center;
|
|
271
|
+
line-height: 0.5;
|
|
272
|
+
font-family: "Segoe UI", Arial, sans-serif;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.avatar--bot > p {
|
|
276
|
+
color: ${this.agentAvatarFontColor};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.avatar--user > p {
|
|
280
|
+
color: ${this.customerAvatarFontColor};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.webchat__bubble__content>div.ms_lcw_webchat_adaptive_card {
|
|
284
|
+
background-color: #FFF;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
div[class="ac-textBlock"] {
|
|
288
|
+
color: #000 !important;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.ms_lcw_webchat_received_message a:link, .ms_lcw_webchat_received_message a:visited, .ms_lcw_webchat_received_message a:hover, .ms_lcw_webchat_received_message a:active {
|
|
292
|
+
color: #FFF;
|
|
293
|
+
}
|
|
294
|
+
<\/style>
|
|
295
|
+
</head>
|
|
296
|
+
`;
|
|
297
|
+
return htmlData;
|
|
298
|
+
}
|
|
299
|
+
createBodyElement() {
|
|
300
|
+
const htmlData = `
|
|
301
|
+
<body>
|
|
302
|
+
<script>
|
|
303
|
+
if (!navigator.onLine) {
|
|
304
|
+
const offlineText = \`${this.networkOfflineMessage}\`;
|
|
305
|
+
document.body.innerHTML = offlineText;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
window.addEventListener("online", () => {
|
|
309
|
+
document.body.innerHTML = \`${this.networkOnlineMessage} <button onclick="window.location.reload()"> Refresh </button>\`;
|
|
310
|
+
});
|
|
311
|
+
<\/script>
|
|
312
|
+
<div id="transcript"></div>
|
|
313
|
+
<script>
|
|
314
|
+
const getIconText = (text) => {
|
|
315
|
+
if (text) {
|
|
316
|
+
const initials = text.split(/\\s/).reduce((response, word) => response += word.slice(0, 1), '');
|
|
317
|
+
if (initials.length > 1) {
|
|
318
|
+
return initials.substring(0, 2).toUpperCase();
|
|
319
|
+
} else {
|
|
320
|
+
return text.substring(0, 2).toUpperCase();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return "";
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const activityMiddleware = () => (next) => (...args) => {
|
|
328
|
+
const [card] = args;
|
|
329
|
+
|
|
330
|
+
if (card.activity) {
|
|
331
|
+
if (card.activity.from && card.activity.from.role === "channel") {
|
|
332
|
+
return () => false;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Incoming text message
|
|
336
|
+
if (card.activity.text && card.activity.from && card.activity.from.role !== "user") {
|
|
337
|
+
return (...renderArgs) => (React.createElement(
|
|
338
|
+
'div',
|
|
339
|
+
{className: 'ms_lcw_webchat_received_message'},
|
|
340
|
+
next(...args)(...renderArgs)
|
|
341
|
+
))
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return next(...args);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const activityStatusMiddleware = () => (next) => (...args) => {
|
|
349
|
+
const [card] = args;
|
|
350
|
+
const {activity} = card;
|
|
351
|
+
|
|
352
|
+
if (activity) {
|
|
353
|
+
const {from, timestamp} = activity;
|
|
354
|
+
|
|
355
|
+
const nameElement = React.createElement(
|
|
356
|
+
'span',
|
|
357
|
+
{className: 'message-name'},
|
|
358
|
+
from.name
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
const formattedDate = new Date(timestamp);
|
|
362
|
+
const formattedTimeString = formattedDate.toLocaleTimeString("en-us", { year: "numeric", month:"numeric", day:"numeric", hour: "2-digit", minute: "2-digit"});
|
|
363
|
+
|
|
364
|
+
const timestampElement = React.createElement(
|
|
365
|
+
'span',
|
|
366
|
+
{className: 'message-timestamp'},
|
|
367
|
+
formattedTimeString
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
return from.name && timestamp && React.createElement('span', null, nameElement, ' - ', timestampElement)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return next(...args);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const avatarMiddleware = () => (next) => (...args) => {
|
|
377
|
+
const [card] = args;
|
|
378
|
+
const {fromUser, activity} = card;
|
|
379
|
+
const initials = getIconText(activity.from.name);
|
|
380
|
+
|
|
381
|
+
const avatarElement = React.createElement(
|
|
382
|
+
"div",
|
|
383
|
+
{className: fromUser? "avatar avatar--user": "avatar avatar--bot"},
|
|
384
|
+
React.createElement(
|
|
385
|
+
"p",
|
|
386
|
+
null,
|
|
387
|
+
\`\${initials}\`
|
|
388
|
+
)
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
return avatarElement;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const attachmentMiddleware = () => (next) => (...args) => {
|
|
395
|
+
const [card] = args;
|
|
396
|
+
const {activity} = card;
|
|
397
|
+
|
|
398
|
+
if (activity) {
|
|
399
|
+
const { activity: { attachments }, attachment } = card;
|
|
400
|
+
|
|
401
|
+
// No attachment
|
|
402
|
+
if (!attachments || !attachments.length || !attachment) {
|
|
403
|
+
return next(...args);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
let { content, contentType } = attachment || { content: "", contentType: "" };
|
|
407
|
+
|
|
408
|
+
// Adaptive card
|
|
409
|
+
if (contentType.startsWith("application/vnd.microsoft.card")) {
|
|
410
|
+
const adaptiveCardElement = React.createElement(
|
|
411
|
+
"div",
|
|
412
|
+
{className: 'ms_lcw_webchat_adaptive_card'},
|
|
413
|
+
next(...args)
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
return adaptiveCardElement;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return next(...args);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineMarkdownSupport) => {
|
|
424
|
+
let markdown;
|
|
425
|
+
if (!disableMarkdownMessageFormatting) {
|
|
426
|
+
markdown = new window.markdownit(
|
|
427
|
+
"default",
|
|
428
|
+
{
|
|
429
|
+
html: true,
|
|
430
|
+
linkify: true,
|
|
431
|
+
breaks: (!disableNewLineMarkdownSupport)
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
} else {
|
|
435
|
+
markdown = new window.markdownit(
|
|
436
|
+
"zero",
|
|
437
|
+
{
|
|
438
|
+
html: true,
|
|
439
|
+
linkify: true,
|
|
440
|
+
breaks: (!disableNewLineMarkdownSupport)
|
|
441
|
+
}
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
markdown.enable([
|
|
445
|
+
"entity",
|
|
446
|
+
"linkify",
|
|
447
|
+
"html_block",
|
|
448
|
+
"html_inline",
|
|
449
|
+
"newline"
|
|
450
|
+
]);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return markdown;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const markdown = createMarkdown(disableMarkdownMessageFormatting, disableNewLineMarkdownSupport);
|
|
457
|
+
const renderMarkdown = (text) => {
|
|
458
|
+
const render = disableNewLineMarkdownSupport? markdown.renderInline.bind(markdown): markdown.render.bind(markdown);
|
|
459
|
+
text = render(text);
|
|
460
|
+
return text;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
const adapter = new TranscriptAdapter();
|
|
464
|
+
const styleOptions = {
|
|
465
|
+
hideSendBox: true,
|
|
466
|
+
backgroundColor: '${this.transcriptBackgroundColor}',
|
|
467
|
+
bubbleBackground: '${this.agentAvatarBackgroundColor}',
|
|
468
|
+
bubbleTextColor: '${this.agentAvatarFontColor}',
|
|
469
|
+
bubbleBorderRadius: 12,
|
|
470
|
+
bubbleNubSize: 1,
|
|
471
|
+
bubbleFromUserBackground: '${this.customerAvatarBackgroundColor}',
|
|
472
|
+
bubbleFromUserTextColor: '${this.customerAvatarFontColor}',
|
|
473
|
+
bubbleFromUserBorderRadius: 12,
|
|
474
|
+
bubbleFromUserNubSize: 1,
|
|
475
|
+
botAvatarInitials: 'C1',
|
|
476
|
+
userAvatarInitials: 'C2'
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
window.WebChat.renderWebChat({
|
|
480
|
+
directLine: adapter,
|
|
481
|
+
styleOptions,
|
|
482
|
+
activityMiddleware,
|
|
483
|
+
activityStatusMiddleware,
|
|
484
|
+
avatarMiddleware,
|
|
485
|
+
attachmentMiddleware,
|
|
486
|
+
renderMarkdown
|
|
487
|
+
},
|
|
488
|
+
document.getElementById('transcript'));
|
|
489
|
+
<\/script>
|
|
490
|
+
</body>
|
|
491
|
+
`;
|
|
492
|
+
return htmlData;
|
|
493
|
+
}
|
|
494
|
+
createHTML() {
|
|
495
|
+
const htmlData = `
|
|
496
|
+
<html>
|
|
497
|
+
${this.createHeadElement()}
|
|
498
|
+
${this.createBodyElement()}
|
|
499
|
+
</html>
|
|
500
|
+
`;
|
|
501
|
+
return htmlData;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const createChatTranscript = async function (transcript, chatSDK) {
|
|
505
|
+
let renderAttachments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
506
|
+
let transcriptOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
507
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
508
|
+
const transcriptMessages = JSON.parse(transcript);
|
|
509
|
+
const convertBlobToBase64 = async blob => {
|
|
510
|
+
return new Promise(resolve => {
|
|
511
|
+
const reader = new FileReader();
|
|
512
|
+
reader.onloadend = () => resolve(reader.result);
|
|
513
|
+
reader.readAsDataURL(blob);
|
|
514
|
+
});
|
|
515
|
+
};
|
|
516
|
+
let messages = transcriptMessages;
|
|
517
|
+
if (renderAttachments) {
|
|
518
|
+
messages = await Promise.all(transcriptMessages.map(async message => {
|
|
519
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
520
|
+
const {
|
|
521
|
+
amsReferences,
|
|
522
|
+
amsMetadata
|
|
523
|
+
} = message;
|
|
524
|
+
if (amsReferences && amsMetadata) {
|
|
525
|
+
const references = JSON.parse(amsReferences);
|
|
526
|
+
const metadata = JSON.parse(amsMetadata);
|
|
527
|
+
const fileMetadata = {
|
|
528
|
+
id: references[0],
|
|
529
|
+
type: metadata[0].contentType
|
|
530
|
+
};
|
|
531
|
+
const blob = await chatSDK.downloadFileAttachment(fileMetadata);
|
|
532
|
+
const base64 = await convertBlobToBase64(blob);
|
|
533
|
+
message.contentUrl = base64;
|
|
534
|
+
}
|
|
535
|
+
return message;
|
|
536
|
+
}));
|
|
537
|
+
}
|
|
538
|
+
const options = {
|
|
539
|
+
...transcriptOptions,
|
|
540
|
+
messages
|
|
541
|
+
};
|
|
542
|
+
const htmlBuilder = new TranscriptHTMLBuilder(options);
|
|
543
|
+
const text = htmlBuilder.createHTML();
|
|
544
|
+
const fileName = `${transcriptOptions.fileName || "transcript"}.html`;
|
|
545
|
+
(0, _utils.createFileAndDownload)(fileName, text, "text/html");
|
|
546
|
+
};
|
|
547
|
+
var _default = createChatTranscript;
|
|
548
|
+
exports.default = _default;
|
|
@@ -107,6 +107,7 @@ _defineProperty(Constants, "PopoutCacheSuffix", "popout");
|
|
|
107
107
|
_defineProperty(Constants, "LWICheckOnVisibilityTimeout", 3 * 60 * 1000);
|
|
108
108
|
// 3 minute
|
|
109
109
|
// Popup mode custom context response event message name
|
|
110
|
+
_defineProperty(Constants, "InitContextParamsRequest", "initContextParamsRequest");
|
|
110
111
|
_defineProperty(Constants, "InitContextParamsResponse", "initContextParamsResponse");
|
|
111
112
|
export const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
|
|
112
113
|
export class HtmlIdNames {}
|
|
@@ -143,6 +144,7 @@ _defineProperty(HtmlAttributeNames, "listItem", "LI");
|
|
|
143
144
|
_defineProperty(HtmlAttributeNames, "unorderedList", "UL");
|
|
144
145
|
_defineProperty(HtmlAttributeNames, "div", "div");
|
|
145
146
|
_defineProperty(HtmlAttributeNames, "aTagName", "a");
|
|
147
|
+
_defineProperty(HtmlAttributeNames, "pTagName", "p");
|
|
146
148
|
_defineProperty(HtmlAttributeNames, "noopenerTag", "noopener");
|
|
147
149
|
_defineProperty(HtmlAttributeNames, "noreferrerTag", "noreferrer");
|
|
148
150
|
_defineProperty(HtmlAttributeNames, "adaptiveCardClassName", "ac-adaptiveCard");
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
3
|
import { LogLevel, TelemetryEvent } from "../../telemetry/TelemetryConstants";
|
|
4
|
+
import { StorageType } from "../../Constants";
|
|
4
5
|
import { TelemetryHelper } from "../../telemetry/TelemetryHelper";
|
|
5
6
|
import { inMemoryDataStore } from "./defaultInMemoryDataStore";
|
|
6
|
-
|
|
7
|
+
export const isCookieAllowed = () => {
|
|
8
|
+
try {
|
|
9
|
+
localStorage;
|
|
10
|
+
sessionStorage;
|
|
11
|
+
return true;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if (!window.TPCWarningLogged) {
|
|
14
|
+
console.warn("Third party cookies blocked.");
|
|
15
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
16
|
+
Event: TelemetryEvent.ThirdPartyCookiesBlocked,
|
|
17
|
+
Description: "Third party cookies are blocked. Cannot access local storage or session storage."
|
|
18
|
+
});
|
|
19
|
+
window.TPCWarningLogged = true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
7
24
|
export const defaultClientDataStoreProvider = function () {
|
|
8
25
|
let cacheTtlinMins = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
9
26
|
let storageType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : StorageType.localStorage;
|
|
10
27
|
let ttlInMs = 0;
|
|
11
|
-
const isCookieAllowed = () => {
|
|
12
|
-
try {
|
|
13
|
-
localStorage;
|
|
14
|
-
sessionStorage;
|
|
15
|
-
return true;
|
|
16
|
-
} catch (error) {
|
|
17
|
-
if (!window.TPCWarningShown) {
|
|
18
|
-
console.warn("Third party cookies blocked.");
|
|
19
|
-
window.TPCWarningShown = true;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
28
|
if (ttlInMs == 0) {
|
|
25
29
|
ttlInMs = cacheTtlinMins * 60 * 1000;
|
|
26
30
|
}
|
|
@@ -158,6 +158,7 @@ export let TelemetryEvent;
|
|
|
158
158
|
TelemetryEvent["SetBotAuthProviderHideCard"] = "SetBotAuthProviderHideCard";
|
|
159
159
|
TelemetryEvent["SetBotAuthProviderDisplayCard"] = "SetBotAuthProviderDisplayCard";
|
|
160
160
|
TelemetryEvent["SetBotAuthProviderNotFound"] = "SetBotAuthProviderNotFound";
|
|
161
|
+
TelemetryEvent["ThirdPartyCookiesBlocked"] = "ThirdPartyCookiesBlocked";
|
|
161
162
|
TelemetryEvent["ProcessingHTMLTextMiddlewareFailed"] = "ProcessingHTMLTextMiddlewareFailed";
|
|
162
163
|
TelemetryEvent["ProcessingSanitizationMiddlewareFailed"] = "ProcessingSanitizationMiddlewareFailed";
|
|
163
164
|
TelemetryEvent["FormatTagsMiddlewareJSONStringifyFailed"] = "FormatTagsMiddlewareJSONStringifyFailed";
|
|
@@ -225,6 +226,7 @@ export class TelemetryConstants {
|
|
|
225
226
|
case TelemetryEvent.OutOfOfficePaneLoaded:
|
|
226
227
|
case TelemetryEvent.ConfirmationPaneLoaded:
|
|
227
228
|
case TelemetryEvent.ProactiveChatPaneLoaded:
|
|
229
|
+
case TelemetryEvent.ThirdPartyCookiesBlocked:
|
|
228
230
|
return ScenarioType.LOAD;
|
|
229
231
|
case TelemetryEvent.PrechatSubmitted:
|
|
230
232
|
case TelemetryEvent.LCWChatButtonClicked:
|