@xapp/chat-widget 1.37.4 → 1.39.0
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/App.d.ts +6 -0
- package/dist/components/ActionItem/ActionItem.d.ts +2 -2
- package/dist/components/ActionItem/ActionItem.stories.d.ts +1 -1
- package/dist/components/ChatMessageBubble/ChatMessageBubble.d.ts +2 -2
- package/dist/components/ChatMessagePart/ChatMessagePart.d.ts +2 -2
- package/dist/components/OptionalLink/OptionalLink.d.ts +2 -2
- package/dist/components/OptionalLink/OptionalLink.stories.d.ts +1 -1
- package/dist/index.css +1 -1
- package/dist/index.es.js +89 -23
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +89 -23
- package/dist/index.js.map +1 -1
- package/dist/store/ChatAction.d.ts +4 -0
- package/dist/tests/App.test.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/retryRequest.d.ts +13 -0
- package/package.json +24 -24
package/dist/index.js
CHANGED
|
@@ -1446,6 +1446,49 @@ function useIsMounted() {
|
|
|
1446
1446
|
return React$1.useCallback(function () { return ref.current; }, []);
|
|
1447
1447
|
}
|
|
1448
1448
|
|
|
1449
|
+
var RetryOptions = /** @class */ (function () {
|
|
1450
|
+
function RetryOptions() {
|
|
1451
|
+
this.retries = 5;
|
|
1452
|
+
this.timeout = 1000;
|
|
1453
|
+
this.log = false;
|
|
1454
|
+
}
|
|
1455
|
+
return RetryOptions;
|
|
1456
|
+
}());
|
|
1457
|
+
var RetryRequest = /** @class */ (function () {
|
|
1458
|
+
function RetryRequest(options) {
|
|
1459
|
+
if (options) {
|
|
1460
|
+
this.options = Object.assign(new RetryOptions(), options);
|
|
1461
|
+
}
|
|
1462
|
+
this.attempts = 0;
|
|
1463
|
+
}
|
|
1464
|
+
RetryRequest.prototype.retry = function (executor) {
|
|
1465
|
+
var _this = this;
|
|
1466
|
+
return new Promise(function (resolve, reject) {
|
|
1467
|
+
if (_this.attempts < _this.options.retries) {
|
|
1468
|
+
setTimeout(function () {
|
|
1469
|
+
_this.attempts++;
|
|
1470
|
+
executor
|
|
1471
|
+
.then(function (response) { return resolve(response); })
|
|
1472
|
+
.catch(function (error) {
|
|
1473
|
+
_this.lastError = error;
|
|
1474
|
+
_this.log("Retry: ".concat(_this.attempts, " : ").concat(JSON.stringify(error)));
|
|
1475
|
+
return _this.retry(executor).then(resolve).catch(reject);
|
|
1476
|
+
});
|
|
1477
|
+
}, _this.options.timeout);
|
|
1478
|
+
}
|
|
1479
|
+
else {
|
|
1480
|
+
reject(_this.lastError);
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1483
|
+
};
|
|
1484
|
+
RetryRequest.prototype.log = function (message) {
|
|
1485
|
+
if (this.options.log && console && console.log) {
|
|
1486
|
+
console.log(message);
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
return RetryRequest;
|
|
1490
|
+
}());
|
|
1491
|
+
|
|
1449
1492
|
var EMAIL_REGEX = "^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$";
|
|
1450
1493
|
// Returns current timestamp
|
|
1451
1494
|
function getCurrentDateString() {
|
|
@@ -1666,17 +1709,18 @@ var Carousel = function (props) {
|
|
|
1666
1709
|
setSetVisibleIndex(newVisibleIndex);
|
|
1667
1710
|
}
|
|
1668
1711
|
}
|
|
1712
|
+
var hasOnlyOneItem = props.list.items.length === 1;
|
|
1669
1713
|
var hasImage = props.list.items.some(function (item) { return item.imageUrl; });
|
|
1670
1714
|
var listItems = props.list.items.map(function (item, itemIndex) {
|
|
1671
1715
|
return (React__default$1["default"].createElement("div", { className: "xappw-carousel-items__item", key: "item-key-".concat(itemIndex) },
|
|
1672
1716
|
React__default$1["default"].createElement(CarouselItem, { item: item, emptyImageVisible: hasImage, onExecute: props.onExecute, onButtonClick: props.onButtonClick, onOpenUrl: props.onOpenUrl })));
|
|
1673
1717
|
});
|
|
1674
1718
|
return (React__default$1["default"].createElement("div", { className: "xappw-carousel" },
|
|
1675
|
-
React__default$1["default"].createElement("div", { className: "xappw-carousel__prev" },
|
|
1676
|
-
React__default$1["default"].createElement(ChevronLeft, { onClick: function () { return scrollMe(-1); } })),
|
|
1677
|
-
React__default$1["default"].createElement("div", { ref: listRef, className: "xappw-carousel-items" }, listItems),
|
|
1678
|
-
React__default$1["default"].createElement("div", { className: "xappw-carousel__next" },
|
|
1679
|
-
React__default$1["default"].createElement(ChevronRight, { onClick: function () { return scrollMe(1); } }))));
|
|
1719
|
+
hasOnlyOneItem && (React__default$1["default"].createElement("div", { className: "xappw-carousel__prev" },
|
|
1720
|
+
React__default$1["default"].createElement(ChevronLeft, { onClick: function () { return scrollMe(-1); } }))),
|
|
1721
|
+
React__default$1["default"].createElement("div", { ref: listRef, className: "xappw-carousel-items ".concat(hasOnlyOneItem ? "xappw-carousel-items--one-item" : "") }, listItems),
|
|
1722
|
+
hasOnlyOneItem && (React__default$1["default"].createElement("div", { className: "xappw-carousel__next" },
|
|
1723
|
+
React__default$1["default"].createElement(ChevronRight, { onClick: function () { return scrollMe(1); } })))));
|
|
1680
1724
|
};
|
|
1681
1725
|
|
|
1682
1726
|
function useDimensions() {
|
|
@@ -1897,19 +1941,21 @@ function throwBadKind$1(x) {
|
|
|
1897
1941
|
|
|
1898
1942
|
function execute(url, behavior) {
|
|
1899
1943
|
var type = behavior.type;
|
|
1900
|
-
if (get("opened")) {
|
|
1901
|
-
set("opened", false);
|
|
1902
|
-
}
|
|
1903
1944
|
switch (type) {
|
|
1904
1945
|
case "newWindow":
|
|
1946
|
+
if (get("opened")) {
|
|
1947
|
+
set("opened", false);
|
|
1948
|
+
}
|
|
1905
1949
|
window.open(url, "callout-option", "toolbar=0,status=0,width=".concat(behavior.width || 1000, ",height=").concat(behavior.height || 700));
|
|
1906
1950
|
break;
|
|
1907
1951
|
case "newTab":
|
|
1952
|
+
if (get("opened")) {
|
|
1953
|
+
set("opened", false);
|
|
1954
|
+
}
|
|
1908
1955
|
window.open(url, "_blank");
|
|
1909
1956
|
break;
|
|
1910
1957
|
case "sameWindow":
|
|
1911
|
-
|
|
1912
|
-
if (get("visible")) {
|
|
1958
|
+
if (!get("opened")) {
|
|
1913
1959
|
set("opened", true);
|
|
1914
1960
|
}
|
|
1915
1961
|
window.open(url, "_self");
|
|
@@ -1941,6 +1987,7 @@ function writeMessage(msg, user) {
|
|
|
1941
1987
|
function executeAction(text, token) {
|
|
1942
1988
|
return function (chatServer) { return function (dispatch, getState) {
|
|
1943
1989
|
var attributes = getState().attributes;
|
|
1990
|
+
attributes = __assign(__assign({}, attributes), { currentUrl: window.location.href });
|
|
1944
1991
|
chatServer.sendChatMsg({ text: text, token: token, attributes: attributes }, function (err) {
|
|
1945
1992
|
if (err) {
|
|
1946
1993
|
log("Error sending message", err);
|
|
@@ -1997,6 +2044,7 @@ function sendFile(file) {
|
|
|
1997
2044
|
user: {
|
|
1998
2045
|
nick: "",
|
|
1999
2046
|
},
|
|
2047
|
+
attributes: { currentUrl: window.location.href },
|
|
2000
2048
|
timestamp: +Date()
|
|
2001
2049
|
}
|
|
2002
2050
|
});
|
|
@@ -2840,12 +2888,11 @@ function convertFromListDisplay(list) {
|
|
|
2840
2888
|
};
|
|
2841
2889
|
}
|
|
2842
2890
|
function convertFromCardDisplay(card) {
|
|
2843
|
-
var _a;
|
|
2844
2891
|
return {
|
|
2845
2892
|
content: card.content,
|
|
2846
2893
|
imageUrl: card.smallImageUrl,
|
|
2847
2894
|
title: card.title,
|
|
2848
|
-
imageActionUrl:
|
|
2895
|
+
imageActionUrl: card === null || card === void 0 ? void 0 : card.imageActionUrl,
|
|
2849
2896
|
buttons: card.buttons ? card.buttons.map(function (button) { return ({
|
|
2850
2897
|
actionUrl: button.openUrlAction,
|
|
2851
2898
|
label: button.title
|
|
@@ -3131,14 +3178,14 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3131
3178
|
};
|
|
3132
3179
|
StentorDirectChat.prototype.setVisitorInfo = function (visitorInfo, cb) {
|
|
3133
3180
|
this.visitorInfo = visitorInfo;
|
|
3134
|
-
this._attributes = this.visitorInfo.attributes;
|
|
3181
|
+
this._attributes = __assign(__assign({}, this.visitorInfo.attributes), { currentUrl: window.location.href });
|
|
3135
3182
|
this._accessToken = this.visitorInfo.accessToken;
|
|
3136
|
-
this.startSession();
|
|
3137
3183
|
// This is for the bot
|
|
3138
3184
|
this.userJoined({
|
|
3139
3185
|
user: this.getBot(undefined),
|
|
3140
3186
|
token: ""
|
|
3141
3187
|
});
|
|
3188
|
+
this.startSession();
|
|
3142
3189
|
cb();
|
|
3143
3190
|
};
|
|
3144
3191
|
StentorDirectChat.prototype.sendChatRating = function () {
|
|
@@ -3258,14 +3305,21 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3258
3305
|
log("Visitor says: ".concat(JSON.stringify(request, undefined, 2)));
|
|
3259
3306
|
// Bot is "typing"
|
|
3260
3307
|
this.typing();
|
|
3261
|
-
return [4 /*yield*/, postMessageToStentor(request, this.config.url, this.config.key).
|
|
3308
|
+
return [4 /*yield*/, new RetryRequest({ retries: 1, timeout: 5000 }).retry(postMessageToStentor(request, this.config.url, this.config.key)).then(function (result) {
|
|
3309
|
+
botResponse = result;
|
|
3310
|
+
}, function (error) {
|
|
3311
|
+
err("POST failed: ".concat(error));
|
|
3312
|
+
//eslint-disable-next-line
|
|
3313
|
+
//@ts-ignore
|
|
3314
|
+
botResponse = { errorText: "Bot doesn't respond. Reason: ".concat(error) };
|
|
3315
|
+
}).catch(function (postError) {
|
|
3262
3316
|
err("POST failed: ".concat(postError.message));
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
};
|
|
3317
|
+
//eslint-disable-next-line
|
|
3318
|
+
//@ts-ignore
|
|
3319
|
+
botResponse = { errorText: "Bot doesn't respond. Reason: ".concat(error) };
|
|
3266
3320
|
})];
|
|
3267
3321
|
case 1:
|
|
3268
|
-
|
|
3322
|
+
_e.sent();
|
|
3269
3323
|
// Bot stopped "typing"
|
|
3270
3324
|
this.stopTyping();
|
|
3271
3325
|
log("Bot says: ".concat(JSON.stringify(botResponse, undefined, 2)));
|
|
@@ -3273,7 +3327,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3273
3327
|
// new session no more
|
|
3274
3328
|
this.isNewSession = false;
|
|
3275
3329
|
responseMessage = responseToMessage(botResponse);
|
|
3276
|
-
if (!
|
|
3330
|
+
if (botResponse.hasOwnProperty("errorText") || !botResponse) {
|
|
3277
3331
|
responseMessage = {
|
|
3278
3332
|
type: "userLeft",
|
|
3279
3333
|
timestamp: now,
|
|
@@ -3300,7 +3354,13 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3300
3354
|
else {
|
|
3301
3355
|
this._userId = "stentor-widget-user-".concat(uuid_1());
|
|
3302
3356
|
}
|
|
3303
|
-
|
|
3357
|
+
if (get("sessionId") !== "") {
|
|
3358
|
+
this._sessionId = get("sessionId");
|
|
3359
|
+
}
|
|
3360
|
+
else {
|
|
3361
|
+
this._sessionId = "stentor-widget-session-".concat(uuid_1());
|
|
3362
|
+
set("sessionId", this._sessionId);
|
|
3363
|
+
}
|
|
3304
3364
|
// This is a flag that is cleared after the first message is sent
|
|
3305
3365
|
this.isNewSession = true;
|
|
3306
3366
|
};
|
|
@@ -7554,7 +7614,7 @@ function useGreeting(active) {
|
|
|
7554
7614
|
visitorId: curr.visitorId,
|
|
7555
7615
|
userId: curr.userId,
|
|
7556
7616
|
accessToken: curr.accessToken,
|
|
7557
|
-
attributes: curr.attributes
|
|
7617
|
+
attributes: __assign(__assign({}, curr.attributes), { currentUrl: window.location.href })
|
|
7558
7618
|
}));
|
|
7559
7619
|
var timeoutId_1 = setTimeout(function () {
|
|
7560
7620
|
var greetingAction = sendGreeting();
|
|
@@ -8495,7 +8555,7 @@ var ChatWidget = function (props) {
|
|
|
8495
8555
|
canCancel = !dockedMode && !staticMode;
|
|
8496
8556
|
}
|
|
8497
8557
|
// Our state - pull from storage
|
|
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];
|
|
8558
|
+
var _o = React$1.useState((!canMinimize && !canCancel) || !!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
8559
|
var _p = React$1.useState(false), typing = _p[0], setTypingState = _p[1]; // false initially
|
|
8500
8560
|
var chatServer = React$1.useContext(ChatServerContext);
|
|
8501
8561
|
var setVisible = React$1.useCallback(function (newVisible) {
|
|
@@ -8557,13 +8617,16 @@ var ChatWidget = function (props) {
|
|
|
8557
8617
|
return visible ? "visible" : "";
|
|
8558
8618
|
}
|
|
8559
8619
|
function minimizeOnClick() {
|
|
8620
|
+
set("opened", false);
|
|
8560
8621
|
setVisible(false);
|
|
8561
8622
|
}
|
|
8562
8623
|
function cancelOnClick() {
|
|
8624
|
+
set("opened", false);
|
|
8563
8625
|
innerDispatch(reset());
|
|
8564
8626
|
setVisible(false);
|
|
8565
8627
|
}
|
|
8566
8628
|
function chatButtonOnClick() {
|
|
8629
|
+
set("opened", true);
|
|
8567
8630
|
setVisible(true);
|
|
8568
8631
|
}
|
|
8569
8632
|
var isOffline = chatState.accountStatus === "offline" && !chatState.isChatting;
|
|
@@ -8707,6 +8770,9 @@ function joinMessages(messages, msg) {
|
|
|
8707
8770
|
|
|
8708
8771
|
function memberJoin(state, detail) {
|
|
8709
8772
|
var _a;
|
|
8773
|
+
if (state.chats.length === 0) {
|
|
8774
|
+
set("sessionId", "");
|
|
8775
|
+
}
|
|
8710
8776
|
if (isAgent(detail.user.nick)) {
|
|
8711
8777
|
var prevAgentInfo = state.agents[detail.user.nick];
|
|
8712
8778
|
return __assign(__assign({}, state), { isChatting: true, chats: (prevAgentInfo === null || prevAgentInfo === void 0 ? void 0 : prevAgentInfo.joined) ? state.chats : joinMessages(state.chats, detail), agents: (_a = {},
|