@microsoft/omnichannel-chat-widget 0.1.0-main.d5846c0 → 0.1.0-main.d80ebb6
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/README.md +32 -0
- package/lib/cjs/common/Constants.js +12 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +4 -2
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +9 -3
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +7 -1
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -3
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +20 -17
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/mesageTimestampMiddleware.js +116 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/esm/common/Constants.js +12 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +4 -2
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +10 -4
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +7 -1
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +7 -4
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +17 -14
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/mesageTimestampMiddleware.js +106 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/types/common/Constants.d.ts +6 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +4 -2
- package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/mesageTimestampMiddleware.d.ts +5 -0
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
- package/package.json +2 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import "@testing-library/jest-dom/extend-expect";
|
|
2
|
+
import { createCardActionMiddleware } from "./cardActionMiddleware";
|
|
3
|
+
describe("cardActionMiddleware test", () => {
|
|
4
|
+
it("createCardActionMiddleware() with undefined botMagicCodeConfig should not change the sign in card url", () => {
|
|
5
|
+
const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
|
|
9
|
+
const args = {
|
|
10
|
+
cardAction: {
|
|
11
|
+
type: "signin",
|
|
12
|
+
value: signInUrl
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const results = createCardActionMiddleware(undefined)()(next)(args);
|
|
16
|
+
expect(signInUrl).toEqual(results.cardAction.value);
|
|
17
|
+
});
|
|
18
|
+
it("createCardActionMiddleware() with botMagicCode enabled should not change the sign in card url", () => {
|
|
19
|
+
const botMagicCodeConfig = {
|
|
20
|
+
disabled: false
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
|
|
27
|
+
const args = {
|
|
28
|
+
cardAction: {
|
|
29
|
+
type: "signin",
|
|
30
|
+
value: signInUrl
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
|
|
34
|
+
expect(args.cardAction.value).toEqual(results.cardAction.value);
|
|
35
|
+
});
|
|
36
|
+
it("createCardActionMiddleware() with botMagicCode disabled & no fwdUrl should not change the sign in card url", () => {
|
|
37
|
+
const botMagicCodeConfig = {
|
|
38
|
+
disabled: true
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
|
|
45
|
+
const args = {
|
|
46
|
+
cardAction: {
|
|
47
|
+
type: "signin",
|
|
48
|
+
value: signInUrl
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
|
|
52
|
+
expect(args.cardAction.value).toEqual(results.cardAction.value);
|
|
53
|
+
});
|
|
54
|
+
it("createCardActionMiddleware() with botMagicCode disabled & fwdUrl should append the fwdUrl in the sign in card url", () => {
|
|
55
|
+
const botMagicCodeConfig = {
|
|
56
|
+
disabled: true,
|
|
57
|
+
fwdUrl: "http://localhost/forwarder.html"
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
|
|
64
|
+
const args = {
|
|
65
|
+
cardAction: {
|
|
66
|
+
type: "signin",
|
|
67
|
+
value: signInUrl
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
|
|
71
|
+
expect(signInUrl === results.cardAction.value).toBe(false);
|
|
72
|
+
expect(results.cardAction.value === `${signInUrl}&fwdUrl=${botMagicCodeConfig.fwdUrl}`).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
it("createCardActionMiddleware() should not append fwdUrl if fwdUrl & sign in card url are not in the same domain", () => {
|
|
75
|
+
const botMagicCodeConfig = {
|
|
76
|
+
disabled: true,
|
|
77
|
+
fwdUrl: "https://localhost/forwarder.html"
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
|
|
84
|
+
const args = {
|
|
85
|
+
cardAction: {
|
|
86
|
+
type: "signin",
|
|
87
|
+
value: signInUrl
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
|
|
91
|
+
expect(signInUrl === results.cardAction.value).toBe(true);
|
|
92
|
+
expect(results.cardAction.value === `${signInUrl}&fwdUrl=${botMagicCodeConfig.fwdUrl}`).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { WebChatActionType } from "../../enums/WebChatActionType";
|
|
2
|
+
import { Constants } from "../../../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
|
3
|
+
|
|
4
|
+
const createMessageTimeStampMiddleware = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
dispatch
|
|
7
|
+
} = _ref;
|
|
8
|
+
return next => action => {
|
|
9
|
+
if (isApplicable(action)) {
|
|
10
|
+
return next(evaluateTagsAndOverrideTimeStamp(action));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return next(action);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const isApplicable = action => {
|
|
18
|
+
return action.type === WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY && isPVAConversation(action) && isPayloadValid(action) && isValidChannel(action);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const isPayloadValid = action => {
|
|
22
|
+
var _action$payload;
|
|
23
|
+
|
|
24
|
+
return action === null || action === void 0 ? void 0 : (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : _action$payload.activity;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const isValidChannel = action => {
|
|
28
|
+
var _action$payload2, _action$payload2$acti;
|
|
29
|
+
|
|
30
|
+
return (action === null || action === void 0 ? void 0 : (_action$payload2 = action.payload) === null || _action$payload2 === void 0 ? void 0 : (_action$payload2$acti = _action$payload2.activity) === null || _action$payload2$acti === void 0 ? void 0 : _action$payload2$acti.channelId) === Constants.acsChannel;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const isPVAConversation = action => {
|
|
34
|
+
return !isTagIncluded(action, Constants.systemMessageTag) && !isTagIncluded(action, Constants.publicMessageTag) && !isRoleUserOn(action);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const isTagIncluded = (action, tag) => {
|
|
38
|
+
return isDataTagsPresent(action) && action.payload.activity.channelData.tags.includes(tag);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const isRoleUserOn = action => {
|
|
42
|
+
var _action$payload3, _action$payload3$acti, _action$payload3$acti2;
|
|
43
|
+
|
|
44
|
+
return (action === null || action === void 0 ? void 0 : (_action$payload3 = action.payload) === null || _action$payload3 === void 0 ? void 0 : (_action$payload3$acti = _action$payload3.activity) === null || _action$payload3$acti === void 0 ? void 0 : (_action$payload3$acti2 = _action$payload3$acti.from) === null || _action$payload3$acti2 === void 0 ? void 0 : _action$payload3$acti2.role) === Constants.userMessageTag;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const overrideTimeStamp = (timestampOriginal, timeStampNew) => {
|
|
48
|
+
return isTimestampValid(timeStampNew) ? timeStampNew : timestampOriginal;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const isTimestampValid = timeStamp => {
|
|
52
|
+
const regex = /(\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])(T)(\d{2})(:{1})(\d{2})(:{1})(\d{2})(.\d+)([Z]{1}))/;
|
|
53
|
+
return regex.test(timeStamp);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const isDataTagsPresent = action => {
|
|
57
|
+
var _action$payload4, _action$payload4$acti, _action$payload4$acti2;
|
|
58
|
+
|
|
59
|
+
return (action === null || action === void 0 ? void 0 : (_action$payload4 = action.payload) === null || _action$payload4 === void 0 ? void 0 : (_action$payload4$acti = _action$payload4.activity) === null || _action$payload4$acti === void 0 ? void 0 : (_action$payload4$acti2 = _action$payload4$acti.channelData) === null || _action$payload4$acti2 === void 0 ? void 0 : _action$payload4$acti2.tags) && action.payload.activity.channelData.tags.length > 0;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const evaluateTagsAndOverrideTimeStamp = action => {
|
|
63
|
+
const tagValue = tagLookup(action, Constants.prefixTimestampTag);
|
|
64
|
+
|
|
65
|
+
if (tagValue) {
|
|
66
|
+
const newTimestamp = extractTimeStamp(tagValue);
|
|
67
|
+
action.payload.activity.timestamp = overrideTimeStamp(action.payload.activity.timestamp, newTimestamp);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return action;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const extractTimeStamp = timeStamp => {
|
|
74
|
+
if (timeStamp && timeStamp.length > 0) {
|
|
75
|
+
const ts = timeStamp.split(Constants.prefixTimestampTag);
|
|
76
|
+
|
|
77
|
+
if (ts && ts.length > 1) {
|
|
78
|
+
return ts[1];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return timeStamp;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const tagLookup = (action, tag) => {
|
|
86
|
+
if (!isDataTagsPresent(action)) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const tags = action.payload.activity.channelData.tags;
|
|
91
|
+
let value;
|
|
92
|
+
|
|
93
|
+
if (tags && tags.length > 0) {
|
|
94
|
+
for (let i = 0; i < tags.length; i++) {
|
|
95
|
+
value = tags[i];
|
|
96
|
+
|
|
97
|
+
if (value && value.indexOf(tag) > -1) {
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default createMessageTimeStampMiddleware;
|
|
@@ -32,4 +32,5 @@ export let LiveChatWidgetActionType;
|
|
|
32
32
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CONVERSATION_ENDED_BY_AGENT"] = 28] = "SET_CONVERSATION_ENDED_BY_AGENT";
|
|
33
33
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_STATE"] = 29] = "SET_WIDGET_STATE";
|
|
34
34
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_LIVE_CHAT_CONTEXT"] = 30] = "SET_LIVE_CHAT_CONTEXT";
|
|
35
|
+
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_BOT_OAUTH_SIGNIN_ID"] = 31] = "SET_BOT_OAUTH_SIGNIN_ID";
|
|
35
36
|
})(LiveChatWidgetActionType || (LiveChatWidgetActionType = {}));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare class Constants {
|
|
2
|
+
static readonly magicCodeBroadcastChannel = "MagicCodeChannel";
|
|
3
|
+
static readonly magicCodeResponseBroadcastChannel = "MagicCodeResponseChannel";
|
|
2
4
|
static readonly systemMessageTag = "system";
|
|
3
5
|
static readonly userMessageTag = "user";
|
|
4
6
|
static readonly historyMessageTag = "history";
|
|
@@ -32,6 +34,10 @@ export declare class Constants {
|
|
|
32
34
|
static readonly queuePositionMessageTag = "queueposition";
|
|
33
35
|
static readonly averageWaitTimeMessageTag = "averagewaittime";
|
|
34
36
|
static readonly message = "message";
|
|
37
|
+
static readonly hiddenTag = "Hidden";
|
|
38
|
+
static readonly prefixTimestampTag = "ServerMessageTimestamp_";
|
|
39
|
+
static readonly acsChannel = "ACS_CHANNEL";
|
|
40
|
+
static readonly publicMessageTag = "public";
|
|
35
41
|
static readonly supportedAdaptiveCardContentTypes: Array<string>;
|
|
36
42
|
static readonly maxUploadFileSize = "500000";
|
|
37
43
|
static readonly imageRegex: RegExp;
|
|
@@ -26,7 +26,7 @@ export declare enum BroadcastEvent {
|
|
|
26
26
|
ProactiveChatStartChat = "ProactiveChatStartChat",
|
|
27
27
|
ProactiveChatStartPopoutChat = "ProactiveChatStartPopoutChat",
|
|
28
28
|
ProactiveChatIsInPopoutMode = "ProactiveChatIsInPopoutMode",
|
|
29
|
-
|
|
29
|
+
ResetProactiveChatParams = "ResetProactiveChatParams",
|
|
30
30
|
InvalidAdaptiveCardFormat = "InvalidAdaptiveCardFormat",
|
|
31
31
|
NewMessageSent = "NewMessageSent",
|
|
32
32
|
NewMessageReceived = "NewMessageReceived",
|
|
@@ -87,7 +87,7 @@ export declare enum TelemetryEvent {
|
|
|
87
87
|
StartChatEventRecevied = "StartChatEventReceived",
|
|
88
88
|
EndChatSDKCall = "EndChatCall",
|
|
89
89
|
EndChatEventReceived = "EndChatEventReceived",
|
|
90
|
-
|
|
90
|
+
WindowClosed = "WindowClosed",
|
|
91
91
|
OnNewMessageFailed = "OnNewMessageFailed",
|
|
92
92
|
OnNewMessageAudioNotificationFailed = "OnNewMessageAudioNotificationFailed",
|
|
93
93
|
DownloadTranscriptResponseNullOrUndefined = "DownloadTranscriptResponseNullOrUndefined",
|
|
@@ -112,6 +112,8 @@ export declare enum TelemetryEvent {
|
|
|
112
112
|
EmailTranscriptButtonClicked = "EmailTranscriptButtonClicked",
|
|
113
113
|
EmailTranscriptCancelButtonClicked = "EmailTranscriptCancelButtonClicked",
|
|
114
114
|
AudioToggleButtonClicked = "AudioToggleButtonClicked",
|
|
115
|
+
SuppressBotMagicCodeSucceeded = "SuppressBotMagicCodeSucceeded",
|
|
116
|
+
SuppressBotMagicCodeFailed = "SuppressBotMagicCodeFailed",
|
|
115
117
|
ProcessingHTMLTextMiddlewareFailed = "ProcessingHTMLTextMiddlewareFailed",
|
|
116
118
|
ProcessingSanitizationMiddlewareFailed = "ProcessingSanitizationMiddlewareFailed",
|
|
117
119
|
FormatTagsMiddlewareJSONStringifyFailed = "FormatTagsMiddlewareJSONStringifyFailed",
|
package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IBotMagicCodeConfig } from "./IBotMagicCodeConfig";
|
|
1
2
|
import { ILiveChatWidgetLocalizedTexts } from "../../../contexts/common/ILiveChatWidgetLocalizedTexts";
|
|
2
3
|
import { IRenderingMiddlewareProps } from "./IRenderingMiddlewareProps";
|
|
3
4
|
import { IStyle } from "@fluentui/react";
|
|
@@ -13,4 +14,5 @@ export interface IWebChatContainerStatefulProps {
|
|
|
13
14
|
storeMiddlewares?: any[];
|
|
14
15
|
renderingMiddlewareProps?: IRenderingMiddlewareProps;
|
|
15
16
|
localizedTexts?: ILiveChatWidgetLocalizedTexts;
|
|
17
|
+
botMagicCode?: IBotMagicCodeConfig;
|
|
16
18
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@testing-library/jest-dom/extend-expect";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/omnichannel-chat-widget",
|
|
3
|
-
"version": "0.1.0-main.
|
|
3
|
+
"version": "0.1.0-main.d80ebb6",
|
|
4
4
|
"description": "Microsoft Omnichannel Chat Widget",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@fluentui/react": "^8.49.1",
|
|
77
|
-
"@microsoft/omnichannel-chat-components": "^0.1.0-main.
|
|
77
|
+
"@microsoft/omnichannel-chat-components": "^0.1.0-main.353ecff",
|
|
78
78
|
"@microsoft/omnichannel-chat-sdk": "1.0.1-main.077d17c",
|
|
79
79
|
"abort-controller-es5": "^2.0.1",
|
|
80
80
|
"dompurify": "^2.3.4",
|