@xapp/chat-widget 1.36.8 → 1.37.2
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/dist/components/CancelButton/CancelButton.d.ts +7 -0
- package/dist/components/CancelButton/index.d.ts +1 -0
- package/dist/components/ChatWidget/ChatWidget.stories.d.ts +1 -0
- package/dist/components/MinimizeButton/MinimizeButton.d.ts +1 -0
- package/dist/components/StatusContainer/StatusContainer.d.ts +2 -0
- package/dist/config/config.d.ts +2 -2
- package/dist/index.css +1 -1
- package/dist/index.es.js +88 -34
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +88 -34
- package/dist/index.js.map +1 -1
- package/dist/store/ChatState.d.ts +7 -0
- package/dist/store/actions/index.d.ts +1 -0
- package/dist/store/actions/resetAction.d.ts +1 -1
- package/dist/xapp/ChatServer.d.ts +29 -0
- package/dist/xapp/ChatServerMessage.d.ts +8 -0
- package/dist/xapp/StentorDirectChat.d.ts +1 -0
- package/package.json +8 -8
- package/dist/components/IconButton/IconButton.d.ts +0 -9
- package/dist/components/IconButton/index.d.ts +0 -1
- package/dist/components/Storybook/messages.d.ts +0 -5
- package/dist/components/Suggestions/SuggestionsGroupItem.d.ts +0 -16
- package/dist/components/Suggestions/SuggestionsItem.d.ts +0 -11
- package/dist/components/Suggestions/data.test.d.ts +0 -1
- package/dist/store/Reset.d.ts +0 -1
- package/dist/utils/__tests__/url-utils.test.d.ts +0 -1
- package/dist/utils/url-utils.d.ts +0 -8
- package/dist/utils/useJsonFetch.d.ts +0 -20
- package/dist/utils/uuid.d.ts +0 -7
- package/dist/utils/uuid.test.d.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -22,8 +22,7 @@ var ActionButton = function (props) {
|
|
|
22
22
|
return (React__default$1["default"].createElement("button", { type: props.type, className: "action-button ".concat(props.addClass), onClick: handleClick }, props.label));
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
var defaultServerUrl =
|
|
26
|
-
process.env.ACCOUNT_KEY;
|
|
25
|
+
var defaultServerUrl = "";
|
|
27
26
|
var ChatConfigContext = React$1.createContext(null);
|
|
28
27
|
function useWidgetEnv() {
|
|
29
28
|
var ctx = React$1.useContext(ChatConfigContext);
|
|
@@ -1898,6 +1897,9 @@ function throwBadKind$1(x) {
|
|
|
1898
1897
|
|
|
1899
1898
|
function execute(url, behavior) {
|
|
1900
1899
|
var type = behavior.type;
|
|
1900
|
+
if (get("opened")) {
|
|
1901
|
+
set("opened", false);
|
|
1902
|
+
}
|
|
1901
1903
|
switch (type) {
|
|
1902
1904
|
case "newWindow":
|
|
1903
1905
|
window.open(url, "callout-option", "toolbar=0,status=0,width=".concat(behavior.width || 1000, ",height=").concat(behavior.height || 700));
|
|
@@ -1906,6 +1908,10 @@ function execute(url, behavior) {
|
|
|
1906
1908
|
window.open(url, "_blank");
|
|
1907
1909
|
break;
|
|
1908
1910
|
case "sameWindow":
|
|
1911
|
+
// For reopen widget after move on same window
|
|
1912
|
+
if (get("visible")) {
|
|
1913
|
+
set("opened", true);
|
|
1914
|
+
}
|
|
1909
1915
|
window.open(url, "_self");
|
|
1910
1916
|
break;
|
|
1911
1917
|
default:
|
|
@@ -1934,7 +1940,8 @@ function writeMessage(msg, user) {
|
|
|
1934
1940
|
|
|
1935
1941
|
function executeAction(text, token) {
|
|
1936
1942
|
return function (chatServer) { return function (dispatch, getState) {
|
|
1937
|
-
|
|
1943
|
+
var attributes = getState().attributes;
|
|
1944
|
+
chatServer.sendChatMsg({ text: text, token: token, attributes: attributes }, function (err) {
|
|
1938
1945
|
if (err) {
|
|
1939
1946
|
log("Error sending message", err);
|
|
1940
1947
|
return;
|
|
@@ -2070,6 +2077,12 @@ function setConnectionStatus(status) {
|
|
|
2070
2077
|
};
|
|
2071
2078
|
}
|
|
2072
2079
|
|
|
2080
|
+
function reset() {
|
|
2081
|
+
return {
|
|
2082
|
+
type: "reset"
|
|
2083
|
+
};
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2073
2086
|
function useChatDispatch() {
|
|
2074
2087
|
return reactRedux.useDispatch();
|
|
2075
2088
|
}
|
|
@@ -2971,6 +2984,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
2971
2984
|
this._userId = "";
|
|
2972
2985
|
this._sessionId = "";
|
|
2973
2986
|
this._accessToken = "";
|
|
2987
|
+
this._attributes = {};
|
|
2974
2988
|
this.config = config;
|
|
2975
2989
|
this.options = options;
|
|
2976
2990
|
this.isNewSession = false;
|
|
@@ -3117,8 +3131,10 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3117
3131
|
};
|
|
3118
3132
|
StentorDirectChat.prototype.setVisitorInfo = function (visitorInfo, cb) {
|
|
3119
3133
|
this.visitorInfo = visitorInfo;
|
|
3134
|
+
this._attributes = this.visitorInfo.attributes;
|
|
3120
3135
|
this._accessToken = this.visitorInfo.accessToken;
|
|
3121
3136
|
this.startSession();
|
|
3137
|
+
// This is for the bot
|
|
3122
3138
|
this.userJoined({
|
|
3123
3139
|
user: this.getBot(undefined),
|
|
3124
3140
|
token: ""
|
|
@@ -3139,23 +3155,27 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3139
3155
|
StentorDirectChat.prototype.postMessage = function (message) {
|
|
3140
3156
|
var _a, _b, _c, _d;
|
|
3141
3157
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
3142
|
-
var request, accessToken, now, permissionRequest, expired, text, granted, userProfile, isEmail, botResponse, responseMessage;
|
|
3158
|
+
var request, userId, sessionId, accessToken, attributes, now, permissionRequest, expired, text, granted, userProfile, isEmail, botResponse, responseMessage;
|
|
3143
3159
|
return __generator$1(this, function (_e) {
|
|
3144
3160
|
switch (_e.label) {
|
|
3145
3161
|
case 0:
|
|
3162
|
+
userId = this._userId;
|
|
3163
|
+
sessionId = this._sessionId;
|
|
3146
3164
|
accessToken = this._accessToken;
|
|
3165
|
+
attributes = this._attributes || {};
|
|
3147
3166
|
now = new Date().getTime();
|
|
3148
3167
|
if (this.isNewSession && !((_a = message === null || message === void 0 ? void 0 : message.msg) === null || _a === void 0 ? void 0 : _a.text)) {
|
|
3149
3168
|
request = {
|
|
3150
3169
|
type: "LAUNCH_REQUEST",
|
|
3151
3170
|
rawQuery: (_b = message === null || message === void 0 ? void 0 : message.msg) === null || _b === void 0 ? void 0 : _b.text,
|
|
3152
|
-
sessionId:
|
|
3153
|
-
userId:
|
|
3171
|
+
sessionId: sessionId,
|
|
3172
|
+
userId: userId,
|
|
3154
3173
|
isNewSession: true,
|
|
3155
3174
|
intentId: "LaunchRequest",
|
|
3156
3175
|
platform: "stentor-platform",
|
|
3157
3176
|
channel: "widget",
|
|
3158
|
-
accessToken: accessToken
|
|
3177
|
+
accessToken: accessToken,
|
|
3178
|
+
attributes: attributes
|
|
3159
3179
|
};
|
|
3160
3180
|
}
|
|
3161
3181
|
else {
|
|
@@ -3165,7 +3185,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3165
3185
|
expired = now - permissionRequest.time > PERMISSION_QUESTION_EXPIRATION_MS;
|
|
3166
3186
|
text = (_d = message.msg.text) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
3167
3187
|
granted = !expired;
|
|
3168
|
-
userProfile = {};
|
|
3188
|
+
userProfile = { id: this._userId };
|
|
3169
3189
|
if (!expired) {
|
|
3170
3190
|
if (permissionRequest.type === "EMAIL") {
|
|
3171
3191
|
isEmail = looksLikeEmail(text);
|
|
@@ -3195,7 +3215,8 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3195
3215
|
intentId: "PermissionGrant",
|
|
3196
3216
|
platform: "stentor-platform",
|
|
3197
3217
|
channel: "widget",
|
|
3198
|
-
accessToken: accessToken
|
|
3218
|
+
accessToken: accessToken,
|
|
3219
|
+
attributes: attributes
|
|
3199
3220
|
};
|
|
3200
3221
|
}
|
|
3201
3222
|
else if (message.type === "custom") {
|
|
@@ -3203,7 +3224,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3203
3224
|
// token: message.msg.token,
|
|
3204
3225
|
sessionId: this._sessionId, userId: this._userId, isNewSession: false,
|
|
3205
3226
|
// intentId: "OptionSelect",
|
|
3206
|
-
platform: "stentor-platform", channel: "widget", accessToken: accessToken });
|
|
3227
|
+
platform: "stentor-platform", channel: "widget", accessToken: accessToken, attributes: attributes });
|
|
3207
3228
|
}
|
|
3208
3229
|
else if (message.msg.token) {
|
|
3209
3230
|
request = {
|
|
@@ -3215,7 +3236,8 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3215
3236
|
intentId: "OptionSelect",
|
|
3216
3237
|
platform: "stentor-platform",
|
|
3217
3238
|
channel: "widget",
|
|
3218
|
-
accessToken: accessToken
|
|
3239
|
+
accessToken: accessToken,
|
|
3240
|
+
attributes: attributes
|
|
3219
3241
|
};
|
|
3220
3242
|
}
|
|
3221
3243
|
else {
|
|
@@ -3228,7 +3250,8 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3228
3250
|
intentId: "NLU_RESULT_PLACEHOLDER",
|
|
3229
3251
|
platform: "stentor-platform",
|
|
3230
3252
|
channel: "widget",
|
|
3231
|
-
accessToken: accessToken
|
|
3253
|
+
accessToken: accessToken,
|
|
3254
|
+
attributes: attributes
|
|
3232
3255
|
};
|
|
3233
3256
|
}
|
|
3234
3257
|
}
|
|
@@ -3269,7 +3292,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3269
3292
|
};
|
|
3270
3293
|
StentorDirectChat.prototype.startSession = function () {
|
|
3271
3294
|
if (this.visitorInfo.visitorId) {
|
|
3272
|
-
this._userId = "
|
|
3295
|
+
this._userId = "".concat(this.visitorInfo.visitorId);
|
|
3273
3296
|
}
|
|
3274
3297
|
else if (this.visitorInfo.email) {
|
|
3275
3298
|
this._userId = "stentor-widget-user-".concat(this.visitorInfo.email);
|
|
@@ -3278,6 +3301,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3278
3301
|
this._userId = "stentor-widget-user-".concat(uuid_1());
|
|
3279
3302
|
}
|
|
3280
3303
|
this._sessionId = "stentor-widget-session-".concat(uuid_1());
|
|
3304
|
+
// This is a flag that is cleared after the first message is sent
|
|
3281
3305
|
this.isNewSession = true;
|
|
3282
3306
|
};
|
|
3283
3307
|
Object.defineProperty(StentorDirectChat.prototype, "userId", {
|
|
@@ -7507,11 +7531,14 @@ function useChatServerVisitorId() {
|
|
|
7507
7531
|
return state.visitorId || state.userId;
|
|
7508
7532
|
});
|
|
7509
7533
|
var visitorAccessToken = reactRedux.useSelector(function (state) { return state.accessToken; });
|
|
7534
|
+
var attributes = reactRedux.useSelector(function (state) { return state.attributes; });
|
|
7510
7535
|
return React$1.useMemo(function () { return ({
|
|
7511
7536
|
dispatch: dispatch,
|
|
7512
7537
|
visitorId: clientVisitorId,
|
|
7513
|
-
accessToken: visitorAccessToken
|
|
7514
|
-
|
|
7538
|
+
accessToken: visitorAccessToken,
|
|
7539
|
+
userId: clientVisitorId,
|
|
7540
|
+
attributes: attributes
|
|
7541
|
+
}); }, [dispatch, clientVisitorId, visitorAccessToken, attributes]);
|
|
7515
7542
|
}
|
|
7516
7543
|
//send whenever server settings or visitor id changes
|
|
7517
7544
|
function useGreeting(active) {
|
|
@@ -7525,7 +7552,9 @@ function useGreeting(active) {
|
|
|
7525
7552
|
curr.dispatch(sendVisitorInfo({
|
|
7526
7553
|
name: "Visitor",
|
|
7527
7554
|
visitorId: curr.visitorId,
|
|
7528
|
-
|
|
7555
|
+
userId: curr.userId,
|
|
7556
|
+
accessToken: curr.accessToken,
|
|
7557
|
+
attributes: curr.attributes
|
|
7529
7558
|
}));
|
|
7530
7559
|
var timeoutId_1 = setTimeout(function () {
|
|
7531
7560
|
var greetingAction = sendGreeting();
|
|
@@ -8136,8 +8165,12 @@ var ServerOffline = function () {
|
|
|
8136
8165
|
React__default$1["default"].createElement("h3", null, "Server is offline"));
|
|
8137
8166
|
};
|
|
8138
8167
|
|
|
8168
|
+
var CancelButton = function (props) {
|
|
8169
|
+
return React__default$1["default"].createElement("div", { className: "cancel-button", onClick: props.onClick });
|
|
8170
|
+
};
|
|
8171
|
+
|
|
8139
8172
|
var MinimizeButton = function (props) {
|
|
8140
|
-
return React__default$1["default"].createElement("div", { className: "minimize-button", onClick: props.onClick });
|
|
8173
|
+
return (React__default$1["default"].createElement("div", { className: "minimize-button ".concat(props.showInRight ? "positionRight" : ""), onClick: props.onClick }));
|
|
8141
8174
|
};
|
|
8142
8175
|
|
|
8143
8176
|
var DEFAULT_STATUS_CONFIG = {
|
|
@@ -8163,12 +8196,14 @@ var StatusContainer = function (props) {
|
|
|
8163
8196
|
React__default$1["default"].createElement("div", { className: "status-text" },
|
|
8164
8197
|
React__default$1["default"].createElement("span", null, getStatusText(props.accountStatus, (_a = props.config) === null || _a === void 0 ? void 0 : _a.status))),
|
|
8165
8198
|
props.canMinimize &&
|
|
8166
|
-
React__default$1["default"].createElement(MinimizeButton, { onClick: props.minimizeOnClick })
|
|
8199
|
+
React__default$1["default"].createElement(MinimizeButton, { onClick: props.minimizeOnClick, showInRight: !props.canCancel }),
|
|
8200
|
+
props.canCancel &&
|
|
8201
|
+
React__default$1["default"].createElement(CancelButton, { onClick: props.cancelOnClick })));
|
|
8167
8202
|
};
|
|
8168
8203
|
|
|
8169
8204
|
function buildStyleContent(theme) {
|
|
8170
8205
|
var _a, _b, _c, _d;
|
|
8171
|
-
return "\n:root {\n".concat(buildVariables(withPrefix("\t--xapp-", union(single("primary-color", theme === null || theme === void 0 ? void 0 : theme.primaryColor), withPrefix("widget-", union(getSize(theme === null || theme === void 0 ? void 0 : theme.size), getMargins(theme === null || theme === void 0 ? void 0 : theme.margin), getBorderStyle(theme === null || theme === void 0 ? void 0 : theme.border))), getChatButtonStyle(theme === null || theme === void 0 ? void 0 : theme.chatButton), withPrefix("header-", getHeaderStyle(theme === null || theme === void 0 ? void 0 : theme.header)), withPrefix("footer-", getFooterStyle(theme === null || theme === void 0 ? void 0 : theme.footer)), withPrefix("content-", union(getBackgroundStyle((_a = theme === null || theme === void 0 ? void 0 : theme.content) === null || _a === void 0 ? void 0 : _a.background))), withPrefix("messages-", getMessagesStyle(theme === null || theme === void 0 ? void 0 : theme.messages)), withPrefix("send-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.sendButton)), withPrefix("menu-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.menuButton)), withPrefix("menu-", getMenuStyle(theme === null || theme === void 0 ? void 0 : theme.menu)), withPrefix("minimize-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.minimizeButton)), withPrefix("carousel-", union(withPrefix("title-", getTextStyle((_b = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _b === void 0 ? void 0 : _b.title)), withPrefix("subtitle-", getTextStyle((_c = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _c === void 0 ? void 0 : _c.subtitle)), withPrefix("action-", getButtonStyle((_d = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _d === void 0 ? void 0 : _d.button)))), withPrefix("input-", getInputStyle(theme === null || theme === void 0 ? void 0 : theme.input)), withPrefix("cta-", getCtaStyle(theme === null || theme === void 0 ? void 0 : theme.cta))))), "\n}");
|
|
8206
|
+
return "\n:root {\n".concat(buildVariables(withPrefix("\t--xapp-", union(single("primary-color", theme === null || theme === void 0 ? void 0 : theme.primaryColor), withPrefix("widget-", union(getSize(theme === null || theme === void 0 ? void 0 : theme.size), getMargins(theme === null || theme === void 0 ? void 0 : theme.margin), getBorderStyle(theme === null || theme === void 0 ? void 0 : theme.border))), getChatButtonStyle(theme === null || theme === void 0 ? void 0 : theme.chatButton), withPrefix("header-", getHeaderStyle(theme === null || theme === void 0 ? void 0 : theme.header)), withPrefix("footer-", getFooterStyle(theme === null || theme === void 0 ? void 0 : theme.footer)), withPrefix("content-", union(getBackgroundStyle((_a = theme === null || theme === void 0 ? void 0 : theme.content) === null || _a === void 0 ? void 0 : _a.background))), withPrefix("messages-", getMessagesStyle(theme === null || theme === void 0 ? void 0 : theme.messages)), withPrefix("send-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.sendButton)), withPrefix("menu-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.menuButton)), withPrefix("menu-", getMenuStyle(theme === null || theme === void 0 ? void 0 : theme.menu)), withPrefix("minimize-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.minimizeButton)), withPrefix("cancel-", getButtonStyle(theme === null || theme === void 0 ? void 0 : theme.cancelButton)), withPrefix("carousel-", union(withPrefix("title-", getTextStyle((_b = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _b === void 0 ? void 0 : _b.title)), withPrefix("subtitle-", getTextStyle((_c = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _c === void 0 ? void 0 : _c.subtitle)), withPrefix("action-", getButtonStyle((_d = theme === null || theme === void 0 ? void 0 : theme.carousel) === null || _d === void 0 ? void 0 : _d.button)))), withPrefix("input-", getInputStyle(theme === null || theme === void 0 ? void 0 : theme.input)), withPrefix("cta-", getCtaStyle(theme === null || theme === void 0 ? void 0 : theme.cta))))), "\n}");
|
|
8172
8207
|
}
|
|
8173
8208
|
function WidgetStylesheet(props) {
|
|
8174
8209
|
var theme = props.theme;
|
|
@@ -8441,7 +8476,7 @@ var ChatWidgetWrapper = function (props) {
|
|
|
8441
8476
|
React__default$1["default"].createElement(ChatWidget, __assign({}, props)))));
|
|
8442
8477
|
};
|
|
8443
8478
|
var ChatWidget = function (props) {
|
|
8444
|
-
var _a, _b, _c, _d, _e, _f;
|
|
8479
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
8445
8480
|
var innerDispatch = useChatDispatch();
|
|
8446
8481
|
var dispatch = useChatServerDispatch();
|
|
8447
8482
|
// From Redux
|
|
@@ -8450,18 +8485,32 @@ var ChatWidget = function (props) {
|
|
|
8450
8485
|
var dockedMode = mode === "docked";
|
|
8451
8486
|
var staticMode = mode === "static";
|
|
8452
8487
|
var modeClass = "widget-container--".concat(mode);
|
|
8453
|
-
var canMinimize = !dockedMode && !staticMode;
|
|
8488
|
+
var canMinimize = !dockedMode && !staticMode && ((_c = (_b = props.config.header) === null || _b === void 0 ? void 0 : _b.actions) === null || _c === void 0 ? void 0 : _c.minimize);
|
|
8489
|
+
var canCancel;
|
|
8490
|
+
// To preserve legacy behavior, cancel needs a little more checks
|
|
8491
|
+
if (typeof ((_e = (_d = props.config.header) === null || _d === void 0 ? void 0 : _d.actions) === null || _e === void 0 ? void 0 : _e.cancel) === "boolean") {
|
|
8492
|
+
canCancel = !dockedMode && !staticMode && ((_g = (_f = props.config.header) === null || _f === void 0 ? void 0 : _f.actions) === null || _g === void 0 ? void 0 : _g.cancel);
|
|
8493
|
+
}
|
|
8494
|
+
else {
|
|
8495
|
+
canCancel = !dockedMode && !staticMode;
|
|
8496
|
+
}
|
|
8454
8497
|
// Our state - pull from storage
|
|
8455
|
-
var
|
|
8456
|
-
var
|
|
8498
|
+
var _o = React$1.useState(!canMinimize || !!get("visible)") || (((_h = props.config) === null || _h === void 0 ? void 0 : _h.autoOpenOnWidth) && window.matchMedia("(min-width: ".concat((_j = props.config) === null || _j === void 0 ? void 0 : _j.autoOpenOnWidth, ")")).matches)), visible = _o[0], setVisibleState = _o[1];
|
|
8499
|
+
var _p = React$1.useState(false), typing = _p[0], setTypingState = _p[1]; // false initially
|
|
8457
8500
|
var chatServer = React$1.useContext(ChatServerContext);
|
|
8458
|
-
|
|
8501
|
+
var setVisible = React$1.useCallback(function (newVisible) {
|
|
8459
8502
|
if (staticMode) {
|
|
8460
8503
|
return;
|
|
8461
8504
|
}
|
|
8462
8505
|
setVisibleState(newVisible);
|
|
8463
8506
|
set("visible", newVisible);
|
|
8464
|
-
}
|
|
8507
|
+
}, [staticMode]);
|
|
8508
|
+
React$1.useEffect(function () {
|
|
8509
|
+
// For reopen widget after move on same window
|
|
8510
|
+
if (get("opened")) {
|
|
8511
|
+
setVisible(true);
|
|
8512
|
+
}
|
|
8513
|
+
}, [setVisible]);
|
|
8465
8514
|
function handleOnChange() {
|
|
8466
8515
|
if (!typing) {
|
|
8467
8516
|
dispatch(sendTyping(true));
|
|
@@ -8510,6 +8559,10 @@ var ChatWidget = function (props) {
|
|
|
8510
8559
|
function minimizeOnClick() {
|
|
8511
8560
|
setVisible(false);
|
|
8512
8561
|
}
|
|
8562
|
+
function cancelOnClick() {
|
|
8563
|
+
innerDispatch(reset());
|
|
8564
|
+
setVisible(false);
|
|
8565
|
+
}
|
|
8513
8566
|
function chatButtonOnClick() {
|
|
8514
8567
|
setVisible(true);
|
|
8515
8568
|
}
|
|
@@ -8553,17 +8606,17 @@ var ChatWidget = function (props) {
|
|
|
8553
8606
|
onConnectionStatusChange(connectionStatus);
|
|
8554
8607
|
}
|
|
8555
8608
|
}, [connectionStatus, onConnectionStatusChange]);
|
|
8556
|
-
useExternalScript((
|
|
8609
|
+
useExternalScript((_k = props.config) === null || _k === void 0 ? void 0 : _k.middlewareUrl);
|
|
8557
8610
|
return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
|
|
8558
8611
|
React__default$1["default"].createElement("div", { className: "widget-container ".concat(modeClass, " ").concat(getVisibilityClass()) },
|
|
8559
8612
|
React__default$1["default"].createElement(WidgetStylesheet, { theme: config === null || config === void 0 ? void 0 : config.theme }),
|
|
8560
|
-
React__default$1["default"].createElement(StatusContainer, { accountStatus: chatState.accountStatus, minimizeOnClick: minimizeOnClick, agent: (
|
|
8613
|
+
React__default$1["default"].createElement(StatusContainer, { accountStatus: chatState.accountStatus, minimizeOnClick: minimizeOnClick, cancelOnClick: cancelOnClick, agent: (_l = chatState.agents["agent:robot"]) === null || _l === void 0 ? void 0 : _l.user, canMinimize: canMinimize, canCancel: canCancel, config: config === null || config === void 0 ? void 0 : config.header }),
|
|
8561
8614
|
React__default$1["default"].createElement(MessageList, { visible: visible, queuePosition: chatState.queuePosition, isChatting: chatState.isChatting, isOffline: isOffline, messages: messages, agents: chatState.agents, lastRatingRequestTimestamp: chatState.lastRatingRequestTimestamp, hasRating: chatState.hasRating, visitorId: chatState.visitorId, messageMiddleware: props.messageMiddleware, onSend: handleSendMessage, onWrite: handleWriteMessage, onOpenUrl: handleOpenUrl }),
|
|
8562
8615
|
React__default$1["default"].createElement("div", { className: "spinner-container ".concat(visible && connectionStatus === "pending" ? "visible" : "") },
|
|
8563
8616
|
React__default$1["default"].createElement("div", { className: "spinner" })),
|
|
8564
8617
|
connectionStatus === "offline" && React__default$1["default"].createElement(ServerOffline, null),
|
|
8565
8618
|
React__default$1["default"].createElement(ChatFooter, { isChatting: chatState.isChatting, onChange: handleOnChange, onSubmit: handleOnSubmit, onFileUpload: handleFileUpload })),
|
|
8566
|
-
React__default$1["default"].createElement(ChatButton, { addClass: getVisibilityClass(), onClick: chatButtonOnClick, config: (
|
|
8619
|
+
React__default$1["default"].createElement(ChatButton, { addClass: getVisibilityClass(), onClick: chatButtonOnClick, config: (_m = props.config) === null || _m === void 0 ? void 0 : _m.cta, visible: visible })));
|
|
8567
8620
|
};
|
|
8568
8621
|
|
|
8569
8622
|
function tryParseJson(str) {
|
|
@@ -8798,7 +8851,7 @@ function createChatStore(config, dataStorage) {
|
|
|
8798
8851
|
if (dataStorage === void 0) { dataStorage = sessionStorage; }
|
|
8799
8852
|
var connection = config.connection;
|
|
8800
8853
|
var storage = new BrowserStateStorage(dataStorage, "xappchat.".concat(connection.serverUrl, ".").concat(connection.accountKey));
|
|
8801
|
-
var defaultState = createDefaultState({ accessToken: config.accessToken, userId: config.userId });
|
|
8854
|
+
var defaultState = createDefaultState({ accessToken: config.accessToken, userId: config.userId, attributes: config.attributes });
|
|
8802
8855
|
var chatReducer = persistStateReducer(storage, defaultState, storeHandler);
|
|
8803
8856
|
var middlewares = [
|
|
8804
8857
|
thunk__default["default"]
|
|
@@ -8808,18 +8861,19 @@ function createChatStore(config, dataStorage) {
|
|
|
8808
8861
|
}
|
|
8809
8862
|
|
|
8810
8863
|
var ChatWidgetContainer = function (props) {
|
|
8811
|
-
var _a, _b, _c;
|
|
8864
|
+
var _a, _b, _c, _d;
|
|
8812
8865
|
var messageMiddleware = useStandardMiddleware();
|
|
8813
8866
|
var connection = useServerConfig(props.config);
|
|
8814
8867
|
var chatStore = React$1.useMemo(function () {
|
|
8815
|
-
var _a, _b;
|
|
8868
|
+
var _a, _b, _c;
|
|
8816
8869
|
return createChatStore({
|
|
8817
8870
|
connection: connection,
|
|
8818
8871
|
userId: (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId,
|
|
8819
|
-
accessToken: (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken
|
|
8872
|
+
accessToken: (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken,
|
|
8873
|
+
attributes: (_c = props.config) === null || _c === void 0 ? void 0 : _c.attributes,
|
|
8820
8874
|
});
|
|
8821
|
-
}, [connection, (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId, (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken]);
|
|
8822
|
-
if ((
|
|
8875
|
+
}, [connection, (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId, (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken, (_c = props.config) === null || _c === void 0 ? void 0 : _c.attributes]);
|
|
8876
|
+
if ((_d = props.config) === null || _d === void 0 ? void 0 : _d.disabled) {
|
|
8823
8877
|
return React__default$1["default"].createElement(React__default$1["default"].Fragment, null);
|
|
8824
8878
|
}
|
|
8825
8879
|
var widgetProps = __assign(__assign({}, props), { messageMiddleware: messageMiddleware });
|