@microsoft/omnichannel-chat-widget 1.7.3-main.5f11aa4 → 1.7.3-main.722a237

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 (45) hide show
  1. package/lib/cjs/components/livechatwidget/LiveChatWidget.js +6 -1
  2. package/lib/cjs/components/livechatwidget/common/getMockChatSDKIfApplicable.js +26 -0
  3. package/lib/cjs/components/livechatwidget/common/overridePropsOnMockIfApplicable.js +41 -0
  4. package/lib/cjs/components/livechatwidget/common/startChat.js +9 -1
  5. package/lib/cjs/components/livechatwidget/interfaces/IMockProps.js +7 -0
  6. package/lib/cjs/components/webchatcontainerstateful/common/DemoChatAdapter.js +87 -0
  7. package/lib/cjs/components/webchatcontainerstateful/common/DemoChatSDK.js +17 -0
  8. package/lib/cjs/components/webchatcontainerstateful/common/DesignerChatAdapter.js +41 -0
  9. package/lib/cjs/components/webchatcontainerstateful/common/DesignerChatSDK.js +17 -0
  10. package/lib/cjs/components/webchatcontainerstateful/common/MockBotCardCommandType.js +14 -0
  11. package/lib/cjs/components/webchatcontainerstateful/common/MockBotCommand.js +19 -0
  12. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +3 -0
  13. package/lib/cjs/components/webchatcontainerstateful/common/utils/attachmentActivityUtils.js +71 -0
  14. package/lib/cjs/components/webchatcontainerstateful/common/utils/chatAdapterUtils.js +90 -0
  15. package/lib/cjs/plugins/newMessageEventHandler.js +4 -2
  16. package/lib/esm/components/livechatwidget/LiveChatWidget.js +6 -1
  17. package/lib/esm/components/livechatwidget/common/getMockChatSDKIfApplicable.js +20 -0
  18. package/lib/esm/components/livechatwidget/common/overridePropsOnMockIfApplicable.js +34 -0
  19. package/lib/esm/components/livechatwidget/common/startChat.js +9 -1
  20. package/lib/esm/components/livechatwidget/interfaces/IMockProps.js +6 -0
  21. package/lib/esm/components/webchatcontainerstateful/common/DemoChatAdapter.js +79 -0
  22. package/lib/esm/components/webchatcontainerstateful/common/DemoChatSDK.js +10 -0
  23. package/lib/esm/components/webchatcontainerstateful/common/DesignerChatAdapter.js +33 -0
  24. package/lib/esm/components/webchatcontainerstateful/common/DesignerChatSDK.js +10 -0
  25. package/lib/esm/components/webchatcontainerstateful/common/MockBotCardCommandType.js +7 -0
  26. package/lib/esm/components/webchatcontainerstateful/common/MockBotCommand.js +12 -0
  27. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +3 -0
  28. package/lib/esm/components/webchatcontainerstateful/common/utils/attachmentActivityUtils.js +61 -0
  29. package/lib/esm/components/webchatcontainerstateful/common/utils/chatAdapterUtils.js +77 -0
  30. package/lib/esm/plugins/newMessageEventHandler.js +4 -2
  31. package/lib/types/components/livechatwidget/common/getMockChatSDKIfApplicable.d.ts +1 -0
  32. package/lib/types/components/livechatwidget/common/overridePropsOnMockIfApplicable.d.ts +3 -0
  33. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
  34. package/lib/types/components/livechatwidget/interfaces/IMockProps.d.ts +8 -0
  35. package/lib/types/components/webchatcontainerstateful/common/DemoChatAdapter.d.ts +10 -0
  36. package/lib/types/components/webchatcontainerstateful/common/DemoChatSDK.d.ts +6 -0
  37. package/lib/types/components/webchatcontainerstateful/common/DesignerChatAdapter.d.ts +8 -0
  38. package/lib/types/components/webchatcontainerstateful/common/DesignerChatSDK.d.ts +6 -0
  39. package/lib/types/components/webchatcontainerstateful/common/MockBotCardCommandType.d.ts +6 -0
  40. package/lib/types/components/webchatcontainerstateful/common/MockBotCommand.d.ts +11 -0
  41. package/lib/types/components/webchatcontainerstateful/common/mockadapter.d.ts +2 -1
  42. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +6 -0
  43. package/lib/types/components/webchatcontainerstateful/common/utils/attachmentActivityUtils.d.ts +9 -0
  44. package/lib/types/components/webchatcontainerstateful/common/utils/chatAdapterUtils.d.ts +9 -0
  45. package/package.json +3 -3
@@ -11,16 +11,21 @@ var _ChatSDKStore = require("../../contexts/ChatSDKStore");
11
11
  var _LiveChatWidgetStateful = _interopRequireDefault(require("./livechatwidgetstateful/LiveChatWidgetStateful"));
12
12
  var _createReducer = require("../../contexts/createReducer");
13
13
  var _LiveChatWidgetContextInitialState = require("../../contexts/common/LiveChatWidgetContextInitialState");
14
+ var _getMockChatSDKIfApplicable = require("./common/getMockChatSDKIfApplicable");
15
+ var _overridePropsOnMockIfApplicable = _interopRequireDefault(require("./common/overridePropsOnMockIfApplicable"));
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
19
  const LiveChatWidget = props => {
20
+ var _props$mock;
18
21
  const reducer = (0, _createReducer.createReducer)();
19
22
  const [state, dispatch] = (0, _react.useReducer)(reducer, (0, _LiveChatWidgetContextInitialState.getLiveChatWidgetContextInitialState)(props));
20
23
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
24
  const [adapter, setAdapter] = (0, _react.useState)(undefined);
25
+ const chatSDK = (0, _getMockChatSDKIfApplicable.getMockChatSDKIfApplicable)(props.chatSDK, props === null || props === void 0 ? void 0 : (_props$mock = props.mock) === null || _props$mock === void 0 ? void 0 : _props$mock.type);
26
+ (0, _overridePropsOnMockIfApplicable.default)(props);
22
27
  return /*#__PURE__*/_react.default.createElement(_ChatSDKStore.ChatSDKStore.Provider, {
23
- value: props.chatSDK
28
+ value: chatSDK
24
29
  }, /*#__PURE__*/_react.default.createElement(_ChatAdapterStore.ChatAdapterStore.Provider, {
25
30
  value: [adapter, setAdapter]
26
31
  }, /*#__PURE__*/_react.default.createElement(_ChatContextStore.ChatContextStore.Provider, {
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getMockChatSDKIfApplicable = void 0;
7
+ var _DemoChatSDK = require("../../webchatcontainerstateful/common/DemoChatSDK");
8
+ var _DesignerChatSDK = require("../../webchatcontainerstateful/common/DesignerChatSDK");
9
+ var _mockchatsdk = require("../../webchatcontainerstateful/common/mockchatsdk");
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ const getMockChatSDKIfApplicable = (chatSDK, type) => {
12
+ if (type) {
13
+ switch (type.toLowerCase()) {
14
+ case "demo":
15
+ chatSDK = new _DemoChatSDK.DemoChatSDK();
16
+ break;
17
+ case "designer":
18
+ chatSDK = new _DesignerChatSDK.DesignerChatSDK();
19
+ break;
20
+ default:
21
+ chatSDK = new _mockchatsdk.MockChatSDK();
22
+ }
23
+ }
24
+ return chatSDK;
25
+ };
26
+ exports.getMockChatSDKIfApplicable = getMockChatSDKIfApplicable;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const overridePropsOnMockIfApplicable = props => {
8
+ var _props$mock, _props$mock2;
9
+ if (props !== null && props !== void 0 && (_props$mock = props.mock) !== null && _props$mock !== void 0 && _props$mock.type && (props === null || props === void 0 ? void 0 : (_props$mock2 = props.mock) === null || _props$mock2 === void 0 ? void 0 : _props$mock2.type.toLowerCase()) === "designer") {
10
+ if (!props.webChatContainerProps) {
11
+ props.webChatContainerProps = {};
12
+ }
13
+ if (!props.webChatContainerProps.webChatProps) {
14
+ props.webChatContainerProps.webChatProps = {};
15
+ }
16
+ if (!props.webChatContainerProps.webChatStyles) {
17
+ props.webChatContainerProps.webChatStyles = {};
18
+ }
19
+ if (!props.webChatContainerProps.webChatProps.overrideLocalizedStrings) {
20
+ props.webChatContainerProps.webChatProps.overrideLocalizedStrings = {};
21
+ }
22
+ props.webChatContainerProps = {
23
+ ...props.webChatContainerProps,
24
+ webChatProps: {
25
+ disabled: true,
26
+ ...props.webChatContainerProps.webChatProps,
27
+ overrideLocalizedStrings: {
28
+ TEXT_INPUT_PLACEHOLDER: "Send a message . . .",
29
+ ...props.webChatContainerProps.webChatProps.overrideLocalizedStrings
30
+ }
31
+ },
32
+ webChatStyles: {
33
+ hideUploadButton: false,
34
+ sendBoxBackground: "rgb(243, 242, 241)",
35
+ ...props.webChatContainerProps.webChatStyles
36
+ }
37
+ };
38
+ }
39
+ };
40
+ var _default = overridePropsOnMockIfApplicable;
41
+ exports.default = _default;
@@ -48,6 +48,7 @@ const setAuthenticationIfApplicable = async (props, chatSDK) => {
48
48
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
49
49
  optionalParams = {}; //Resetting to ensure no stale values
50
50
  widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
51
+
51
52
  // reconnect > chat from cache
52
53
  if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
53
54
  const shouldStartChatNormally = await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
@@ -69,7 +70,11 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
69
70
  // Setting Proactive chat settings
70
71
  const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
71
72
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
72
- await setAuthenticationIfApplicable(props, chatSDK);
73
+
74
+ // Setting auth settings to OC API to retrieve existing persistent chat session before start chat if any
75
+ if ((0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
76
+ await setAuthenticationIfApplicable(props, chatSDK);
77
+ }
73
78
 
74
79
  //Setting PreChat and intiate chat
75
80
  await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
@@ -167,6 +172,9 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
167
172
  Description: "Widget loading started"
168
173
  });
169
174
 
175
+ // Auth token retrieval needs to happen during start chat to support pop-out chat
176
+ await setAuthenticationIfApplicable(props, chatSDK);
177
+
170
178
  //Check if chat retrieved from cache
171
179
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
172
180
  var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ var LiveChatWidgetMockType;
4
+ (function (LiveChatWidgetMockType) {
5
+ LiveChatWidgetMockType["Test"] = "Test";
6
+ LiveChatWidgetMockType["Demo"] = "Demo";
7
+ })(LiveChatWidgetMockType || (LiveChatWidgetMockType = {}));
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DemoChatAdapter = void 0;
7
+ require("rxjs/add/operator/share");
8
+ require("rxjs/add/observable/of");
9
+ var _Observable = require("rxjs/Observable");
10
+ var _mockadapter = _interopRequireDefault(require("./mockadapter"));
11
+ var _chatAdapterUtils = require("./utils/chatAdapterUtils");
12
+ var _attachmentActivityUtils = require("./utils/attachmentActivityUtils");
13
+ var _MockBotCommand = _interopRequireDefault(require("./MockBotCommand"));
14
+ var _MockBotCardCommandType = _interopRequireDefault(require("./MockBotCardCommandType"));
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ class DemoChatAdapter extends _mockadapter.default {
17
+ constructor() {
18
+ super();
19
+ setTimeout(() => {
20
+ (0, _chatAdapterUtils.postSystemMessageActivity)(this.activityObserver, "You're currently using a demo.", 0);
21
+ (0, _chatAdapterUtils.postBotMessageActivity)(this.activityObserver, "Type `/help` to learn more", undefined, 0); // send init message from bot
22
+ }, 1000);
23
+ }
24
+ postBotCommandsActivity() {
25
+ let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
26
+ (0, _chatAdapterUtils.postBotAttachmentActivity)(this.activityObserver, [{
27
+ contentType: "application/vnd.microsoft.card.thumbnail",
28
+ content: {
29
+ buttons: [{
30
+ title: "Send system message",
31
+ type: "imBack",
32
+ value: "send system message"
33
+ }, {
34
+ title: "Send typing",
35
+ type: "imBack",
36
+ value: "send typing"
37
+ }, {
38
+ title: "Send bot message",
39
+ type: "imBack",
40
+ value: "send bot message"
41
+ }],
42
+ title: "Commands"
43
+ }
44
+ }], delay);
45
+ }
46
+ postActivity(activity) {
47
+ if (activity) {
48
+ (0, _chatAdapterUtils.postEchoActivity)(this.activityObserver, activity, _chatAdapterUtils.customerUser);
49
+ if (activity.text) {
50
+ switch (true) {
51
+ case activity.text === _MockBotCommand.default.Help:
52
+ this.postBotCommandsActivity();
53
+ break;
54
+ case activity.text === _MockBotCommand.default.SendSystemMessage:
55
+ (0, _chatAdapterUtils.postSystemMessageActivity)(this.activityObserver, "Contoso has joined the chat.");
56
+ break;
57
+ case activity.text === _MockBotCommand.default.SendTyping:
58
+ (0, _chatAdapterUtils.postBotTypingActivity)(this.activityObserver);
59
+ break;
60
+ case activity.text === _MockBotCommand.default.SendAttachment:
61
+ (0, _chatAdapterUtils.postBotAttachmentActivity)(this.activityObserver, [(0, _attachmentActivityUtils.createJpgFileAttachment)()]);
62
+ break;
63
+ case activity.text === _MockBotCommand.default.SendBotMessage:
64
+ (0, _chatAdapterUtils.postBotMessageActivity)(this.activityObserver, "Hi, how can I help you?");
65
+ break;
66
+ case activity.text === `${_MockBotCommand.default.Card} ${_MockBotCardCommandType.default.Signin}`:
67
+ (0, _chatAdapterUtils.postBotAttachmentActivity)(this.activityObserver, [(0, _attachmentActivityUtils.createSigninCardAttachment)()]);
68
+ break;
69
+ case activity.text === `${_MockBotCommand.default.Card} ${_MockBotCardCommandType.default.Hero}`:
70
+ (0, _chatAdapterUtils.postBotAttachmentActivity)(this.activityObserver, [(0, _attachmentActivityUtils.createHeroCardAttachment)()]);
71
+ break;
72
+ case activity.text === `${_MockBotCommand.default.Card} ${_MockBotCardCommandType.default.Thumbnail}`:
73
+ (0, _chatAdapterUtils.postBotAttachmentActivity)(this.activityObserver, [(0, _attachmentActivityUtils.createThumbnailCardAttachment)()]);
74
+ break;
75
+ case activity.text.startsWith(`${_MockBotCommand.default.Bot} `):
76
+ (0, _chatAdapterUtils.postBotMessageActivity)(this.activityObserver, activity.text.substring(5));
77
+ break;
78
+ case activity.text.startsWith(`${_MockBotCommand.default.System} `):
79
+ (0, _chatAdapterUtils.postSystemMessageActivity)(this.activityObserver, activity.text.substring(8));
80
+ break;
81
+ }
82
+ }
83
+ }
84
+ return _Observable.Observable.of(activity.id || "");
85
+ }
86
+ }
87
+ exports.DemoChatAdapter = DemoChatAdapter;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DemoChatSDK = void 0;
7
+ var _DemoChatAdapter = require("./DemoChatAdapter");
8
+ var _mockchatsdk = require("./mockchatsdk");
9
+ class DemoChatSDK extends _mockchatsdk.MockChatSDK {
10
+ constructor() {
11
+ super();
12
+ }
13
+ createChatAdapter() {
14
+ return new _DemoChatAdapter.DemoChatAdapter();
15
+ }
16
+ }
17
+ exports.DemoChatSDK = DemoChatSDK;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DesignerChatAdapter = void 0;
7
+ var _Observable = require("rxjs/Observable");
8
+ var _mockadapter = _interopRequireDefault(require("./mockadapter"));
9
+ var _chatAdapterUtils = require("./utils/chatAdapterUtils");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ class DesignerChatAdapter extends _mockadapter.default {
12
+ constructor() {
13
+ super();
14
+ setTimeout(() => {
15
+ (0, _chatAdapterUtils.postBotMessageActivity)(this.activityObserver, "Id venenatis a condimentum vitae?", undefined, 0);
16
+ this.postUserActivity("Diam donec adipiscing tristique risus nec feugiat in fermentum", 0);
17
+ (0, _chatAdapterUtils.postSystemMessageActivity)(this.activityObserver, "We are finding the best agent for your inquiry, please hold ...", 100);
18
+ (0, _chatAdapterUtils.postSystemMessageActivity)(this.activityObserver, "John has joined the chat", 100);
19
+ (0, _chatAdapterUtils.postBotMessageActivity)(this.activityObserver, "Neque viverra justo nec ultrices dui sapien eget mi proin", undefined, 100);
20
+ }, 1000);
21
+ }
22
+ postUserActivity(text) {
23
+ let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
24
+ setTimeout(() => {
25
+ (0, _chatAdapterUtils.postEchoActivity)(this.activityObserver, {
26
+ text,
27
+ from: {
28
+ ..._chatAdapterUtils.customerUser
29
+ },
30
+ type: "message"
31
+ }, _chatAdapterUtils.customerUser, 0);
32
+ }, delay);
33
+ }
34
+ postActivity(activity) {
35
+ if (activity) {
36
+ (0, _chatAdapterUtils.postEchoActivity)(this.activityObserver, activity, _chatAdapterUtils.customerUser);
37
+ }
38
+ return _Observable.Observable.of(activity.id || "");
39
+ }
40
+ }
41
+ exports.DesignerChatAdapter = DesignerChatAdapter;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DesignerChatSDK = void 0;
7
+ var _DesignerChatAdapter = require("./DesignerChatAdapter");
8
+ var _mockchatsdk = require("./mockchatsdk");
9
+ class DesignerChatSDK extends _mockchatsdk.MockChatSDK {
10
+ constructor() {
11
+ super();
12
+ }
13
+ createChatAdapter() {
14
+ return new _DesignerChatAdapter.DesignerChatAdapter();
15
+ }
16
+ }
17
+ exports.DesignerChatSDK = DesignerChatSDK;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var MockBotCardCommandType;
8
+ (function (MockBotCardCommandType) {
9
+ MockBotCardCommandType["Hero"] = "hero";
10
+ MockBotCardCommandType["Signin"] = "signin";
11
+ MockBotCardCommandType["Thumbnail"] = "thumbnail";
12
+ })(MockBotCardCommandType || (MockBotCardCommandType = {}));
13
+ var _default = MockBotCardCommandType;
14
+ exports.default = _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var MockBotCommand;
8
+ (function (MockBotCommand) {
9
+ MockBotCommand["Bot"] = "/bot";
10
+ MockBotCommand["Card"] = "/card";
11
+ MockBotCommand["Help"] = "/help";
12
+ MockBotCommand["SendAttachment"] = "send attachment";
13
+ MockBotCommand["SendBotMessage"] = "send bot message";
14
+ MockBotCommand["SendSystemMessage"] = "send system message";
15
+ MockBotCommand["SendTyping"] = "send typing";
16
+ MockBotCommand["System"] = "/system";
17
+ })(MockBotCommand || (MockBotCommand = {}));
18
+ var _default = MockBotCommand;
19
+ exports.default = _default;
@@ -21,6 +21,9 @@ class MockChatSDK {
21
21
  orgUrl: "https://contoso.crm.dynamics.com"
22
22
  });
23
23
  }
24
+ async initialize() {
25
+ return this.getLiveChatConfig();
26
+ }
24
27
  async startChat() {
25
28
  await this.sleep(1000);
26
29
  }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createThumbnailCardAttachment = exports.createSigninCardAttachment = exports.createJpgFileAttachment = exports.createHeroCardAttachment = void 0;
7
+ const createJpgFileAttachment = () => {
8
+ return {
9
+ contentType: "image/jpeg",
10
+ name: "600x400.jpg",
11
+ contentUrl: "https://raw.githubusercontent.com/microsoft/omnichannel-chat-sdk/e7e75d4ede351e1cf2e52f13860d2284848c4af0/playwright/public/images/600x400.jpg"
12
+ };
13
+ };
14
+ exports.createJpgFileAttachment = createJpgFileAttachment;
15
+ const createHeroCardAttachment = () => {
16
+ return {
17
+ contentType: "application/vnd.microsoft.card.hero",
18
+ content: {
19
+ buttons: [{
20
+ title: "Bellevue",
21
+ type: "imBack",
22
+ value: "Bellevue"
23
+ }, {
24
+ title: "Redmond",
25
+ type: "imBack",
26
+ value: "Redmond"
27
+ }, {
28
+ title: "Seattle",
29
+ type: "imBack",
30
+ value: "Seattle"
31
+ }],
32
+ title: "Choose your location"
33
+ }
34
+ };
35
+ };
36
+ exports.createHeroCardAttachment = createHeroCardAttachment;
37
+ const createThumbnailCardAttachment = () => {
38
+ return {
39
+ contentType: "application/vnd.microsoft.card.thumbnail",
40
+ content: {
41
+ title: "Microsoft",
42
+ subtitle: "Our mission is to empower every person and every organization on the planet to achieve more.",
43
+ text: "Microsoft creates platforms and tools powered by AI to deliver innovative solutions that meet the evolving needs of our customers. The technology company is committed to making AI available broadly and doing so responsibly, with a mission to empower every person and every organization on the planet to achieve more.",
44
+ images: [{
45
+ alt: "Microsoft logo",
46
+ url: "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31" // logo from https://microsoft.com
47
+ }],
48
+
49
+ buttons: [{
50
+ title: "Learn more",
51
+ type: "openUrl",
52
+ value: "https://www.microsoft.com/"
53
+ }]
54
+ }
55
+ };
56
+ };
57
+ exports.createThumbnailCardAttachment = createThumbnailCardAttachment;
58
+ const createSigninCardAttachment = () => {
59
+ return {
60
+ contentType: "application/vnd.microsoft.card.signin",
61
+ content: {
62
+ text: "Please login",
63
+ buttons: [{
64
+ type: "signin",
65
+ title: "Signin",
66
+ value: "https://login.live.com/"
67
+ }]
68
+ }
69
+ };
70
+ };
71
+ exports.createSigninCardAttachment = createSigninCardAttachment;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.postSystemMessageActivity = exports.postEchoActivity = exports.postBotTypingActivity = exports.postBotMessageActivity = exports.postBotAttachmentActivity = exports.customerUser = exports.botUser = void 0;
7
+ var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
8
+ const customerUser = {
9
+ id: "usedId",
10
+ name: "User",
11
+ role: "user"
12
+ };
13
+ exports.customerUser = customerUser;
14
+ const botUser = {
15
+ id: "botId",
16
+ name: "Bot",
17
+ role: "bot"
18
+ };
19
+
20
+ // WebChat expects an "echo" activity to confirm the message has been sent successfully
21
+ exports.botUser = botUser;
22
+ const postEchoActivity = function (activityObserver, activity, user) {
23
+ let delay = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1000;
24
+ const echoActivity = {
25
+ ...activity,
26
+ id: (0, _omnichannelChatSdk.uuidv4)(),
27
+ from: {
28
+ ...activity.from,
29
+ ...user
30
+ },
31
+ timestamp: new Date().toISOString()
32
+ };
33
+ setTimeout(() => {
34
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next(echoActivity); // mock message sent activity
35
+ }, delay);
36
+ };
37
+ exports.postEchoActivity = postEchoActivity;
38
+ const postBotMessageActivity = function (activityObserver, text) {
39
+ let tags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
40
+ let delay = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1000;
41
+ setTimeout(() => {
42
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next({
43
+ id: (0, _omnichannelChatSdk.uuidv4)(),
44
+ from: {
45
+ ...botUser
46
+ },
47
+ text,
48
+ type: "message",
49
+ channelData: {
50
+ tags
51
+ },
52
+ timestamp: new Date().toISOString()
53
+ });
54
+ }, delay);
55
+ };
56
+ exports.postBotMessageActivity = postBotMessageActivity;
57
+ const postSystemMessageActivity = function (activityObserver, text) {
58
+ let delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
59
+ postBotMessageActivity(activityObserver, text, "system", delay);
60
+ };
61
+ exports.postSystemMessageActivity = postSystemMessageActivity;
62
+ const postBotTypingActivity = function (activityObserver) {
63
+ let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
64
+ setTimeout(() => {
65
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next({
66
+ id: (0, _omnichannelChatSdk.uuidv4)(),
67
+ from: {
68
+ ...botUser
69
+ },
70
+ type: "typing"
71
+ });
72
+ }, delay);
73
+ };
74
+ exports.postBotTypingActivity = postBotTypingActivity;
75
+ const postBotAttachmentActivity = function (activityObserver) {
76
+ let attachments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
77
+ let delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
78
+ setTimeout(() => {
79
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next({
80
+ id: (0, _omnichannelChatSdk.uuidv4)(),
81
+ from: {
82
+ ...botUser
83
+ },
84
+ attachments,
85
+ type: "message",
86
+ timestamp: new Date().toISOString()
87
+ });
88
+ }, delay);
89
+ };
90
+ exports.postBotAttachmentActivity = postBotAttachmentActivity;
@@ -20,7 +20,7 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
20
20
  const raiseMessageEvent = (activity, isHistoryMessage) => {
21
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
22
  const polyfillMessagePayloadForEvent = payload => {
23
- var _activity$conversatio, _TelemetryManager$Int;
23
+ var _activity$conversatio, _TelemetryManager$Int, _attachments;
24
24
  return {
25
25
  ...payload,
26
26
  channelData: activity === null || activity === void 0 ? void 0 : activity.channelData,
@@ -29,7 +29,9 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
29
29
  id: activity === null || activity === void 0 ? void 0 : activity.id,
30
30
  isChatComplete: false,
31
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- text: activity === null || activity === void 0 ? void 0 : activity.text
32
+ text: activity === null || activity === void 0 ? void 0 : activity.text,
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ attachment: (activity === null || activity === void 0 ? void 0 : (_attachments = activity.attachments) === null || _attachments === void 0 ? void 0 : _attachments.length) >= 1 ? activity === null || activity === void 0 ? void 0 : activity.attachments : []
33
35
  };
34
36
  };
35
37
  if ((activity === null || activity === void 0 ? void 0 : activity.type) === _Constants.Constants.message) {
@@ -5,13 +5,18 @@ import { ChatSDKStore } from "../../contexts/ChatSDKStore";
5
5
  import LiveChatWidgetStateful from "./livechatwidgetstateful/LiveChatWidgetStateful";
6
6
  import { createReducer } from "../../contexts/createReducer";
7
7
  import { getLiveChatWidgetContextInitialState } from "../../contexts/common/LiveChatWidgetContextInitialState";
8
+ import { getMockChatSDKIfApplicable } from "./common/getMockChatSDKIfApplicable";
9
+ import overridePropsOnMockIfApplicable from "./common/overridePropsOnMockIfApplicable";
8
10
  export const LiveChatWidget = props => {
11
+ var _props$mock;
9
12
  const reducer = createReducer();
10
13
  const [state, dispatch] = useReducer(reducer, getLiveChatWidgetContextInitialState(props));
11
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
15
  const [adapter, setAdapter] = useState(undefined);
16
+ const chatSDK = getMockChatSDKIfApplicable(props.chatSDK, props === null || props === void 0 ? void 0 : (_props$mock = props.mock) === null || _props$mock === void 0 ? void 0 : _props$mock.type);
17
+ overridePropsOnMockIfApplicable(props);
13
18
  return /*#__PURE__*/React.createElement(ChatSDKStore.Provider, {
14
- value: props.chatSDK
19
+ value: chatSDK
15
20
  }, /*#__PURE__*/React.createElement(ChatAdapterStore.Provider, {
16
21
  value: [adapter, setAdapter]
17
22
  }, /*#__PURE__*/React.createElement(ChatContextStore.Provider, {
@@ -0,0 +1,20 @@
1
+ import { DemoChatSDK } from "../../webchatcontainerstateful/common/DemoChatSDK";
2
+ import { DesignerChatSDK } from "../../webchatcontainerstateful/common/DesignerChatSDK";
3
+ import { MockChatSDK } from "../../webchatcontainerstateful/common/mockchatsdk";
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ export const getMockChatSDKIfApplicable = (chatSDK, type) => {
7
+ if (type) {
8
+ switch (type.toLowerCase()) {
9
+ case "demo":
10
+ chatSDK = new DemoChatSDK();
11
+ break;
12
+ case "designer":
13
+ chatSDK = new DesignerChatSDK();
14
+ break;
15
+ default:
16
+ chatSDK = new MockChatSDK();
17
+ }
18
+ }
19
+ return chatSDK;
20
+ };
@@ -0,0 +1,34 @@
1
+ const overridePropsOnMockIfApplicable = props => {
2
+ var _props$mock, _props$mock2;
3
+ if (props !== null && props !== void 0 && (_props$mock = props.mock) !== null && _props$mock !== void 0 && _props$mock.type && (props === null || props === void 0 ? void 0 : (_props$mock2 = props.mock) === null || _props$mock2 === void 0 ? void 0 : _props$mock2.type.toLowerCase()) === "designer") {
4
+ if (!props.webChatContainerProps) {
5
+ props.webChatContainerProps = {};
6
+ }
7
+ if (!props.webChatContainerProps.webChatProps) {
8
+ props.webChatContainerProps.webChatProps = {};
9
+ }
10
+ if (!props.webChatContainerProps.webChatStyles) {
11
+ props.webChatContainerProps.webChatStyles = {};
12
+ }
13
+ if (!props.webChatContainerProps.webChatProps.overrideLocalizedStrings) {
14
+ props.webChatContainerProps.webChatProps.overrideLocalizedStrings = {};
15
+ }
16
+ props.webChatContainerProps = {
17
+ ...props.webChatContainerProps,
18
+ webChatProps: {
19
+ disabled: true,
20
+ ...props.webChatContainerProps.webChatProps,
21
+ overrideLocalizedStrings: {
22
+ TEXT_INPUT_PLACEHOLDER: "Send a message . . .",
23
+ ...props.webChatContainerProps.webChatProps.overrideLocalizedStrings
24
+ }
25
+ },
26
+ webChatStyles: {
27
+ hideUploadButton: false,
28
+ sendBoxBackground: "rgb(243, 242, 241)",
29
+ ...props.webChatContainerProps.webChatStyles
30
+ }
31
+ };
32
+ }
33
+ };
34
+ export default overridePropsOnMockIfApplicable;
@@ -43,6 +43,7 @@ const setAuthenticationIfApplicable = async (props, chatSDK) => {
43
43
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
44
44
  optionalParams = {}; //Resetting to ensure no stale values
45
45
  widgetInstanceId = getWidgetCacheIdfromProps(props);
46
+
46
47
  // reconnect > chat from cache
47
48
  if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
48
49
  const shouldStartChatNormally = await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
@@ -64,7 +65,11 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
64
65
  // Setting Proactive chat settings
65
66
  const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
66
67
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
67
- await setAuthenticationIfApplicable(props, chatSDK);
68
+
69
+ // Setting auth settings to OC API to retrieve existing persistent chat session before start chat if any
70
+ if (isPersistentEnabled(props.chatConfig)) {
71
+ await setAuthenticationIfApplicable(props, chatSDK);
72
+ }
68
73
 
69
74
  //Setting PreChat and intiate chat
70
75
  await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
@@ -160,6 +165,9 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
160
165
  Description: "Widget loading started"
161
166
  });
162
167
 
168
+ // Auth token retrieval needs to happen during start chat to support pop-out chat
169
+ await setAuthenticationIfApplicable(props, chatSDK);
170
+
163
171
  //Check if chat retrieved from cache
164
172
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
165
173
  var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
@@ -0,0 +1,6 @@
1
+ var LiveChatWidgetMockType;
2
+ (function (LiveChatWidgetMockType) {
3
+ LiveChatWidgetMockType["Test"] = "Test";
4
+ LiveChatWidgetMockType["Demo"] = "Demo";
5
+ })(LiveChatWidgetMockType || (LiveChatWidgetMockType = {}));
6
+ export {};
@@ -0,0 +1,79 @@
1
+ import "rxjs/add/operator/share";
2
+ import "rxjs/add/observable/of";
3
+ import { Observable } from "rxjs/Observable";
4
+ import MockAdapter from "./mockadapter";
5
+ import { customerUser, postBotMessageActivity, postBotAttachmentActivity, postBotTypingActivity, postEchoActivity, postSystemMessageActivity } from "./utils/chatAdapterUtils";
6
+ import { createHeroCardAttachment, createJpgFileAttachment, createSigninCardAttachment, createThumbnailCardAttachment } from "./utils/attachmentActivityUtils";
7
+ import MockBotCommand from "./MockBotCommand";
8
+ import MockBotCardCommandType from "./MockBotCardCommandType";
9
+ export class DemoChatAdapter extends MockAdapter {
10
+ constructor() {
11
+ super();
12
+ setTimeout(() => {
13
+ postSystemMessageActivity(this.activityObserver, "You're currently using a demo.", 0);
14
+ postBotMessageActivity(this.activityObserver, "Type `/help` to learn more", undefined, 0); // send init message from bot
15
+ }, 1000);
16
+ }
17
+ postBotCommandsActivity() {
18
+ let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
19
+ postBotAttachmentActivity(this.activityObserver, [{
20
+ contentType: "application/vnd.microsoft.card.thumbnail",
21
+ content: {
22
+ buttons: [{
23
+ title: "Send system message",
24
+ type: "imBack",
25
+ value: "send system message"
26
+ }, {
27
+ title: "Send typing",
28
+ type: "imBack",
29
+ value: "send typing"
30
+ }, {
31
+ title: "Send bot message",
32
+ type: "imBack",
33
+ value: "send bot message"
34
+ }],
35
+ title: "Commands"
36
+ }
37
+ }], delay);
38
+ }
39
+ postActivity(activity) {
40
+ if (activity) {
41
+ postEchoActivity(this.activityObserver, activity, customerUser);
42
+ if (activity.text) {
43
+ switch (true) {
44
+ case activity.text === MockBotCommand.Help:
45
+ this.postBotCommandsActivity();
46
+ break;
47
+ case activity.text === MockBotCommand.SendSystemMessage:
48
+ postSystemMessageActivity(this.activityObserver, "Contoso has joined the chat.");
49
+ break;
50
+ case activity.text === MockBotCommand.SendTyping:
51
+ postBotTypingActivity(this.activityObserver);
52
+ break;
53
+ case activity.text === MockBotCommand.SendAttachment:
54
+ postBotAttachmentActivity(this.activityObserver, [createJpgFileAttachment()]);
55
+ break;
56
+ case activity.text === MockBotCommand.SendBotMessage:
57
+ postBotMessageActivity(this.activityObserver, "Hi, how can I help you?");
58
+ break;
59
+ case activity.text === `${MockBotCommand.Card} ${MockBotCardCommandType.Signin}`:
60
+ postBotAttachmentActivity(this.activityObserver, [createSigninCardAttachment()]);
61
+ break;
62
+ case activity.text === `${MockBotCommand.Card} ${MockBotCardCommandType.Hero}`:
63
+ postBotAttachmentActivity(this.activityObserver, [createHeroCardAttachment()]);
64
+ break;
65
+ case activity.text === `${MockBotCommand.Card} ${MockBotCardCommandType.Thumbnail}`:
66
+ postBotAttachmentActivity(this.activityObserver, [createThumbnailCardAttachment()]);
67
+ break;
68
+ case activity.text.startsWith(`${MockBotCommand.Bot} `):
69
+ postBotMessageActivity(this.activityObserver, activity.text.substring(5));
70
+ break;
71
+ case activity.text.startsWith(`${MockBotCommand.System} `):
72
+ postSystemMessageActivity(this.activityObserver, activity.text.substring(8));
73
+ break;
74
+ }
75
+ }
76
+ }
77
+ return Observable.of(activity.id || "");
78
+ }
79
+ }
@@ -0,0 +1,10 @@
1
+ import { DemoChatAdapter } from "./DemoChatAdapter";
2
+ import { MockChatSDK } from "./mockchatsdk";
3
+ export class DemoChatSDK extends MockChatSDK {
4
+ constructor() {
5
+ super();
6
+ }
7
+ createChatAdapter() {
8
+ return new DemoChatAdapter();
9
+ }
10
+ }
@@ -0,0 +1,33 @@
1
+ import { Observable } from "rxjs/Observable";
2
+ import MockAdapter from "./mockadapter";
3
+ import { customerUser, postBotMessageActivity, postEchoActivity, postSystemMessageActivity } from "./utils/chatAdapterUtils";
4
+ export class DesignerChatAdapter extends MockAdapter {
5
+ constructor() {
6
+ super();
7
+ setTimeout(() => {
8
+ postBotMessageActivity(this.activityObserver, "Id venenatis a condimentum vitae?", undefined, 0);
9
+ this.postUserActivity("Diam donec adipiscing tristique risus nec feugiat in fermentum", 0);
10
+ postSystemMessageActivity(this.activityObserver, "We are finding the best agent for your inquiry, please hold ...", 100);
11
+ postSystemMessageActivity(this.activityObserver, "John has joined the chat", 100);
12
+ postBotMessageActivity(this.activityObserver, "Neque viverra justo nec ultrices dui sapien eget mi proin", undefined, 100);
13
+ }, 1000);
14
+ }
15
+ postUserActivity(text) {
16
+ let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
17
+ setTimeout(() => {
18
+ postEchoActivity(this.activityObserver, {
19
+ text,
20
+ from: {
21
+ ...customerUser
22
+ },
23
+ type: "message"
24
+ }, customerUser, 0);
25
+ }, delay);
26
+ }
27
+ postActivity(activity) {
28
+ if (activity) {
29
+ postEchoActivity(this.activityObserver, activity, customerUser);
30
+ }
31
+ return Observable.of(activity.id || "");
32
+ }
33
+ }
@@ -0,0 +1,10 @@
1
+ import { DesignerChatAdapter } from "./DesignerChatAdapter";
2
+ import { MockChatSDK } from "./mockchatsdk";
3
+ export class DesignerChatSDK extends MockChatSDK {
4
+ constructor() {
5
+ super();
6
+ }
7
+ createChatAdapter() {
8
+ return new DesignerChatAdapter();
9
+ }
10
+ }
@@ -0,0 +1,7 @@
1
+ var MockBotCardCommandType;
2
+ (function (MockBotCardCommandType) {
3
+ MockBotCardCommandType["Hero"] = "hero";
4
+ MockBotCardCommandType["Signin"] = "signin";
5
+ MockBotCardCommandType["Thumbnail"] = "thumbnail";
6
+ })(MockBotCardCommandType || (MockBotCardCommandType = {}));
7
+ export default MockBotCardCommandType;
@@ -0,0 +1,12 @@
1
+ var MockBotCommand;
2
+ (function (MockBotCommand) {
3
+ MockBotCommand["Bot"] = "/bot";
4
+ MockBotCommand["Card"] = "/card";
5
+ MockBotCommand["Help"] = "/help";
6
+ MockBotCommand["SendAttachment"] = "send attachment";
7
+ MockBotCommand["SendBotMessage"] = "send bot message";
8
+ MockBotCommand["SendSystemMessage"] = "send system message";
9
+ MockBotCommand["SendTyping"] = "send typing";
10
+ MockBotCommand["System"] = "/system";
11
+ })(MockBotCommand || (MockBotCommand = {}));
12
+ export default MockBotCommand;
@@ -14,6 +14,9 @@ export class MockChatSDK {
14
14
  orgUrl: "https://contoso.crm.dynamics.com"
15
15
  });
16
16
  }
17
+ async initialize() {
18
+ return this.getLiveChatConfig();
19
+ }
17
20
  async startChat() {
18
21
  await this.sleep(1000);
19
22
  }
@@ -0,0 +1,61 @@
1
+ export const createJpgFileAttachment = () => {
2
+ return {
3
+ contentType: "image/jpeg",
4
+ name: "600x400.jpg",
5
+ contentUrl: "https://raw.githubusercontent.com/microsoft/omnichannel-chat-sdk/e7e75d4ede351e1cf2e52f13860d2284848c4af0/playwright/public/images/600x400.jpg"
6
+ };
7
+ };
8
+ export const createHeroCardAttachment = () => {
9
+ return {
10
+ contentType: "application/vnd.microsoft.card.hero",
11
+ content: {
12
+ buttons: [{
13
+ title: "Bellevue",
14
+ type: "imBack",
15
+ value: "Bellevue"
16
+ }, {
17
+ title: "Redmond",
18
+ type: "imBack",
19
+ value: "Redmond"
20
+ }, {
21
+ title: "Seattle",
22
+ type: "imBack",
23
+ value: "Seattle"
24
+ }],
25
+ title: "Choose your location"
26
+ }
27
+ };
28
+ };
29
+ export const createThumbnailCardAttachment = () => {
30
+ return {
31
+ contentType: "application/vnd.microsoft.card.thumbnail",
32
+ content: {
33
+ title: "Microsoft",
34
+ subtitle: "Our mission is to empower every person and every organization on the planet to achieve more.",
35
+ text: "Microsoft creates platforms and tools powered by AI to deliver innovative solutions that meet the evolving needs of our customers. The technology company is committed to making AI available broadly and doing so responsibly, with a mission to empower every person and every organization on the planet to achieve more.",
36
+ images: [{
37
+ alt: "Microsoft logo",
38
+ url: "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31" // logo from https://microsoft.com
39
+ }],
40
+
41
+ buttons: [{
42
+ title: "Learn more",
43
+ type: "openUrl",
44
+ value: "https://www.microsoft.com/"
45
+ }]
46
+ }
47
+ };
48
+ };
49
+ export const createSigninCardAttachment = () => {
50
+ return {
51
+ contentType: "application/vnd.microsoft.card.signin",
52
+ content: {
53
+ text: "Please login",
54
+ buttons: [{
55
+ type: "signin",
56
+ title: "Signin",
57
+ value: "https://login.live.com/"
58
+ }]
59
+ }
60
+ };
61
+ };
@@ -0,0 +1,77 @@
1
+ import { uuidv4 } from "@microsoft/omnichannel-chat-sdk";
2
+ export const customerUser = {
3
+ id: "usedId",
4
+ name: "User",
5
+ role: "user"
6
+ };
7
+ export const botUser = {
8
+ id: "botId",
9
+ name: "Bot",
10
+ role: "bot"
11
+ };
12
+
13
+ // WebChat expects an "echo" activity to confirm the message has been sent successfully
14
+ export const postEchoActivity = function (activityObserver, activity, user) {
15
+ let delay = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1000;
16
+ const echoActivity = {
17
+ ...activity,
18
+ id: uuidv4(),
19
+ from: {
20
+ ...activity.from,
21
+ ...user
22
+ },
23
+ timestamp: new Date().toISOString()
24
+ };
25
+ setTimeout(() => {
26
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next(echoActivity); // mock message sent activity
27
+ }, delay);
28
+ };
29
+ export const postBotMessageActivity = function (activityObserver, text) {
30
+ let tags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
31
+ let delay = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1000;
32
+ setTimeout(() => {
33
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next({
34
+ id: uuidv4(),
35
+ from: {
36
+ ...botUser
37
+ },
38
+ text,
39
+ type: "message",
40
+ channelData: {
41
+ tags
42
+ },
43
+ timestamp: new Date().toISOString()
44
+ });
45
+ }, delay);
46
+ };
47
+ export const postSystemMessageActivity = function (activityObserver, text) {
48
+ let delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
49
+ postBotMessageActivity(activityObserver, text, "system", delay);
50
+ };
51
+ export const postBotTypingActivity = function (activityObserver) {
52
+ let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
53
+ setTimeout(() => {
54
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next({
55
+ id: uuidv4(),
56
+ from: {
57
+ ...botUser
58
+ },
59
+ type: "typing"
60
+ });
61
+ }, delay);
62
+ };
63
+ export const postBotAttachmentActivity = function (activityObserver) {
64
+ let attachments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
65
+ let delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
66
+ setTimeout(() => {
67
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next({
68
+ id: uuidv4(),
69
+ from: {
70
+ ...botUser
71
+ },
72
+ attachments,
73
+ type: "message",
74
+ timestamp: new Date().toISOString()
75
+ });
76
+ }, delay);
77
+ };
@@ -14,7 +14,7 @@ export const createOnNewAdapterActivityHandler = (chatId, userId) => {
14
14
  const raiseMessageEvent = (activity, isHistoryMessage) => {
15
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
  const polyfillMessagePayloadForEvent = payload => {
17
- var _activity$conversatio, _TelemetryManager$Int;
17
+ var _activity$conversatio, _TelemetryManager$Int, _attachments;
18
18
  return {
19
19
  ...payload,
20
20
  channelData: activity === null || activity === void 0 ? void 0 : activity.channelData,
@@ -23,7 +23,9 @@ export const createOnNewAdapterActivityHandler = (chatId, userId) => {
23
23
  id: activity === null || activity === void 0 ? void 0 : activity.id,
24
24
  isChatComplete: false,
25
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- text: activity === null || activity === void 0 ? void 0 : activity.text
26
+ text: activity === null || activity === void 0 ? void 0 : activity.text,
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ attachment: (activity === null || activity === void 0 ? void 0 : (_attachments = activity.attachments) === null || _attachments === void 0 ? void 0 : _attachments.length) >= 1 ? activity === null || activity === void 0 ? void 0 : activity.attachments : []
27
29
  };
28
30
  };
29
31
  if ((activity === null || activity === void 0 ? void 0 : activity.type) === Constants.message) {
@@ -0,0 +1 @@
1
+ export declare const getMockChatSDKIfApplicable: (chatSDK: any, type?: string | undefined) => any;
@@ -0,0 +1,3 @@
1
+ import { ILiveChatWidgetProps } from "../interfaces/ILiveChatWidgetProps";
2
+ declare const overridePropsOnMockIfApplicable: (props: ILiveChatWidgetProps) => void;
3
+ export default overridePropsOnMockIfApplicable;
@@ -25,6 +25,7 @@ import { IPostChatSurveyPaneStatefulProps } from "../../postchatsurveypanestatef
25
25
  import { IScrollBarProps } from "./IScrollBarProps";
26
26
  import { IDraggableChatWidgetProps } from "./IDraggableChatWidgetProps";
27
27
  import { INotificationPaneProps } from "@microsoft/omnichannel-chat-components/lib/types/components/notificationpane/interfaces/INotificationPaneProps";
28
+ import { IMockProps } from "./IMockProps";
28
29
  export interface ILiveChatWidgetProps {
29
30
  audioNotificationProps?: IAudioNotificationProps;
30
31
  callingContainerProps?: ICallingContainerProps;
@@ -61,4 +62,5 @@ export interface ILiveChatWidgetProps {
61
62
  allowSdkChatSupport?: boolean;
62
63
  initialCustomContext?: any;
63
64
  draggableChatWidgetProps?: IDraggableChatWidgetProps;
65
+ mock?: IMockProps;
64
66
  }
@@ -0,0 +1,8 @@
1
+ declare enum LiveChatWidgetMockType {
2
+ Test = "Test",
3
+ Demo = "Demo"
4
+ }
5
+ export interface IMockProps {
6
+ type: LiveChatWidgetMockType;
7
+ }
8
+ export {};
@@ -0,0 +1,10 @@
1
+ import "rxjs/add/operator/share";
2
+ import "rxjs/add/observable/of";
3
+ import { Message } from "botframework-directlinejs";
4
+ import { Observable } from "rxjs/Observable";
5
+ import MockAdapter from "./mockadapter";
6
+ export declare class DemoChatAdapter extends MockAdapter {
7
+ constructor();
8
+ private postBotCommandsActivity;
9
+ postActivity(activity: Message): Observable<string>;
10
+ }
@@ -0,0 +1,6 @@
1
+ import { DemoChatAdapter } from "./DemoChatAdapter";
2
+ import { MockChatSDK } from "./mockchatsdk";
3
+ export declare class DemoChatSDK extends MockChatSDK {
4
+ constructor();
5
+ createChatAdapter(): DemoChatAdapter;
6
+ }
@@ -0,0 +1,8 @@
1
+ import { Message } from "botframework-directlinejs";
2
+ import { Observable } from "rxjs/Observable";
3
+ import MockAdapter from "./mockadapter";
4
+ export declare class DesignerChatAdapter extends MockAdapter {
5
+ constructor();
6
+ private postUserActivity;
7
+ postActivity(activity: Message): Observable<string>;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { DesignerChatAdapter } from "./DesignerChatAdapter";
2
+ import { MockChatSDK } from "./mockchatsdk";
3
+ export declare class DesignerChatSDK extends MockChatSDK {
4
+ constructor();
5
+ createChatAdapter(): DesignerChatAdapter;
6
+ }
@@ -0,0 +1,6 @@
1
+ declare enum MockBotCardCommandType {
2
+ Hero = "hero",
3
+ Signin = "signin",
4
+ Thumbnail = "thumbnail"
5
+ }
6
+ export default MockBotCardCommandType;
@@ -0,0 +1,11 @@
1
+ declare enum MockBotCommand {
2
+ Bot = "/bot",
3
+ Card = "/card",
4
+ Help = "/help",
5
+ SendAttachment = "send attachment",
6
+ SendBotMessage = "send bot message",
7
+ SendSystemMessage = "send system message",
8
+ SendTyping = "send typing",
9
+ System = "/system"
10
+ }
11
+ export default MockBotCommand;
@@ -3,8 +3,9 @@ import "rxjs/add/observable/of";
3
3
  import { Activity, ConnectionStatus, Message } from "botframework-directlinejs";
4
4
  import { BehaviorSubject } from "rxjs";
5
5
  import { Observable } from "rxjs/Observable";
6
+ import { Subscriber } from "rxjs/Subscriber";
6
7
  export default class MockAdapter {
7
- private activityObserver?;
8
+ activityObserver?: Subscriber<Activity>;
8
9
  activity$: Observable<Activity>;
9
10
  connectionStatus$: BehaviorSubject<ConnectionStatus>;
10
11
  constructor();
@@ -8,6 +8,12 @@ export declare class MockChatSDK {
8
8
  orgId: string;
9
9
  orgUrl: string;
10
10
  };
11
+ initialize(): Promise<{
12
+ LiveWSAndLiveChatEngJoin: {
13
+ msdyn_postconversationsurveyenable: string;
14
+ msdyn_conversationmode: string;
15
+ };
16
+ }>;
11
17
  startChat(): Promise<void>;
12
18
  endChat(): null;
13
19
  getChatToken(): null;
@@ -0,0 +1,9 @@
1
+ import { HeroCard, Signin, Thumbnail } from "botframework-directlinejs";
2
+ export declare const createJpgFileAttachment: () => {
3
+ contentType: string;
4
+ name: string;
5
+ contentUrl: string;
6
+ };
7
+ export declare const createHeroCardAttachment: () => HeroCard;
8
+ export declare const createThumbnailCardAttachment: () => Thumbnail;
9
+ export declare const createSigninCardAttachment: () => Signin;
@@ -0,0 +1,9 @@
1
+ import { Activity, Attachment, Message, User } from "botframework-directlinejs";
2
+ import { Subscriber } from "rxjs/Subscriber";
3
+ export declare const customerUser: User;
4
+ export declare const botUser: User;
5
+ export declare const postEchoActivity: (activityObserver: Subscriber<Activity> | undefined, activity: Message, user: User, delay?: number) => void;
6
+ export declare const postBotMessageActivity: (activityObserver: Subscriber<Activity> | undefined, text: string, tags?: string, delay?: number) => void;
7
+ export declare const postSystemMessageActivity: (activityObserver: Subscriber<Activity> | undefined, text: string, delay?: number) => void;
8
+ export declare const postBotTypingActivity: (activityObserver: Subscriber<Activity> | undefined, delay?: number) => void;
9
+ export declare const postBotAttachmentActivity: (activityObserver: Subscriber<Activity> | undefined, attachments?: Attachment[], delay?: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.7.3-main.5f11aa4",
3
+ "version": "1.7.3-main.722a237",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -75,9 +75,9 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@microsoft/omnichannel-chat-components": "1.1.5",
78
- "@microsoft/omnichannel-chat-sdk": "^1.9.5",
78
+ "@microsoft/omnichannel-chat-sdk": "^1.9.6",
79
79
  "abort-controller-es5": "^2.0.1",
80
- "dompurify": "^2.3.4",
80
+ "dompurify": "^2.5.4",
81
81
  "markdown-it": "^12.3.2",
82
82
  "markdown-it-attrs": "^4.1.6",
83
83
  "markdown-it-attrs-es5": "^2.0.2",