@xapp/chat-widget 1.52.6 → 1.53.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/index.css +2 -2
- package/dist/index.es.js +463 -11
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +463 -11
- package/dist/index.js.map +1 -1
- package/dist/store/ChatAction.d.ts +1 -1
- package/dist/utils/PersistentStorage.d.ts +1 -1
- package/dist/utils/compiler/models.d.ts +1 -1
- package/dist/utils/requestFromMessage.d.ts +4 -0
- package/dist/utils/requestToMessage.d.ts +12 -0
- package/dist/xapp/StentorRouterChat.d.ts +66 -0
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -2919,6 +2919,7 @@ function convertFromListDisplay(list) {
|
|
|
2919
2919
|
var itemButtons = item.buttons;
|
|
2920
2920
|
if (itemButtons && itemButtons.length > 0) {
|
|
2921
2921
|
responseItem.buttons = itemButtons.map(function (button) { return ({
|
|
2922
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2922
2923
|
actionUrl: button.openUrlAction,
|
|
2923
2924
|
label: button.title
|
|
2924
2925
|
}); });
|
|
@@ -3097,7 +3098,7 @@ function getConfigurableMessagesConfig(messages) {
|
|
|
3097
3098
|
return config;
|
|
3098
3099
|
}
|
|
3099
3100
|
|
|
3100
|
-
var PERMISSION_QUESTION_EXPIRATION_MS = 300000; // 5 minutes
|
|
3101
|
+
var PERMISSION_QUESTION_EXPIRATION_MS$1 = 300000; // 5 minutes
|
|
3101
3102
|
// interface UserLeaveMessage {
|
|
3102
3103
|
// readonly user: ChatUserInfo;
|
|
3103
3104
|
// readonly token: string; //todo: what is this
|
|
@@ -3274,7 +3275,17 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3274
3275
|
};
|
|
3275
3276
|
StentorDirectChat.prototype.setVisitorInfo = function (visitorInfo, cb) {
|
|
3276
3277
|
this.visitorInfo = visitorInfo;
|
|
3277
|
-
this._attributes = __assign(
|
|
3278
|
+
this._attributes = __assign({}, this.visitorInfo.attributes);
|
|
3279
|
+
// do not set currentUrl if localhost, localhost is not liked by some firewalls, like AWS WAF
|
|
3280
|
+
var href = new URL(window.location.href);
|
|
3281
|
+
if (href === null || href === void 0 ? void 0 : href.host.toLowerCase().startsWith("localhost")) {
|
|
3282
|
+
// we still need to communicate it is localhost though so we make this boolean
|
|
3283
|
+
this._attributes.isLocal = true;
|
|
3284
|
+
}
|
|
3285
|
+
else {
|
|
3286
|
+
// not localhost, set it
|
|
3287
|
+
this._attributes.currentUrl = window.location.href;
|
|
3288
|
+
}
|
|
3278
3289
|
this._accessToken = this.visitorInfo.accessToken;
|
|
3279
3290
|
// This is for the bot
|
|
3280
3291
|
this.userJoined({
|
|
@@ -3326,13 +3337,13 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3326
3337
|
permissionRequest = (_c = message.msg) === null || _c === void 0 ? void 0 : _c.permissionRequest;
|
|
3327
3338
|
if (permissionRequest) {
|
|
3328
3339
|
message = __assign(__assign({}, message), { msg: __assign(__assign({}, message.msg), { permissionRequest: undefined }) });
|
|
3329
|
-
expired = now - permissionRequest.time > PERMISSION_QUESTION_EXPIRATION_MS;
|
|
3340
|
+
expired = now - permissionRequest.time > PERMISSION_QUESTION_EXPIRATION_MS$1;
|
|
3330
3341
|
text = (_d = message.msg.text) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
3331
3342
|
granted = !expired;
|
|
3332
3343
|
userProfile = { id: this._userId };
|
|
3333
3344
|
if (!expired) {
|
|
3334
3345
|
if (permissionRequest.type === "EMAIL") {
|
|
3335
|
-
isEmail = looksLikeEmail(text);
|
|
3346
|
+
isEmail = looksLikeEmail$1(text);
|
|
3336
3347
|
granted = isEmail;
|
|
3337
3348
|
userProfile.email = this.visitorInfo.email;
|
|
3338
3349
|
userProfile.name = this.visitorInfo.displayName;
|
|
@@ -3519,7 +3530,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3519
3530
|
});
|
|
3520
3531
|
return StentorDirectChat;
|
|
3521
3532
|
}());
|
|
3522
|
-
function looksLikeEmail(email) {
|
|
3533
|
+
function looksLikeEmail$1(email) {
|
|
3523
3534
|
var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
3524
3535
|
return re.test(String(email).toLowerCase());
|
|
3525
3536
|
}
|
|
@@ -3552,6 +3563,436 @@ var StentorLocalChat = /** @class */ (function () {
|
|
|
3552
3563
|
return StentorLocalChat;
|
|
3553
3564
|
}());
|
|
3554
3565
|
|
|
3566
|
+
/*! Copyright (c) 2022, XAPPmedia */
|
|
3567
|
+
var PERMISSION_QUESTION_EXPIRATION_MS = 300000; // 5 minutes
|
|
3568
|
+
function requestFromMessage(message, userId, isNewSession, sessionId, accessToken, attributes) {
|
|
3569
|
+
var _a, _b, _c, _d;
|
|
3570
|
+
var request;
|
|
3571
|
+
var now = new Date().getTime();
|
|
3572
|
+
if (isNewSession && !((_a = message === null || message === void 0 ? void 0 : message.msg) === null || _a === void 0 ? void 0 : _a.text)) {
|
|
3573
|
+
request = {
|
|
3574
|
+
type: "LAUNCH_REQUEST",
|
|
3575
|
+
rawQuery: (_b = message === null || message === void 0 ? void 0 : message.msg) === null || _b === void 0 ? void 0 : _b.text,
|
|
3576
|
+
sessionId: sessionId,
|
|
3577
|
+
userId: userId,
|
|
3578
|
+
isNewSession: true,
|
|
3579
|
+
intentId: "LaunchRequest",
|
|
3580
|
+
platform: "stentor-platform",
|
|
3581
|
+
channel: "widget",
|
|
3582
|
+
accessToken: accessToken,
|
|
3583
|
+
attributes: attributes
|
|
3584
|
+
};
|
|
3585
|
+
}
|
|
3586
|
+
else {
|
|
3587
|
+
// Pending permission request?
|
|
3588
|
+
var permissionRequest = (_c = message.msg) === null || _c === void 0 ? void 0 : _c.permissionRequest;
|
|
3589
|
+
if (permissionRequest) {
|
|
3590
|
+
message = __assign(__assign({}, message), { msg: __assign(__assign({}, message.msg), { permissionRequest: undefined }) });
|
|
3591
|
+
var expired = now - permissionRequest.time > PERMISSION_QUESTION_EXPIRATION_MS;
|
|
3592
|
+
var text = (_d = message.msg.text) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
|
3593
|
+
var granted = !expired;
|
|
3594
|
+
var userProfile = { id: this._userId };
|
|
3595
|
+
if (!expired) {
|
|
3596
|
+
if (permissionRequest.type === "EMAIL") {
|
|
3597
|
+
var isEmail = looksLikeEmail(text);
|
|
3598
|
+
granted = isEmail;
|
|
3599
|
+
userProfile.email = this.visitorInfo.email;
|
|
3600
|
+
userProfile.name = this.visitorInfo.displayName;
|
|
3601
|
+
this.visitorInfo.email = text;
|
|
3602
|
+
}
|
|
3603
|
+
if (permissionRequest.type === "LOCATION_PRECISE") {
|
|
3604
|
+
granted = !!message.msg.location;
|
|
3605
|
+
userProfile.preciseLocation = message.msg.location ? {
|
|
3606
|
+
coordinates: {
|
|
3607
|
+
latitude: message.msg.location.latitude,
|
|
3608
|
+
longitude: message.msg.location.longitude
|
|
3609
|
+
}
|
|
3610
|
+
} : undefined;
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
request = {
|
|
3614
|
+
type: "PERMISSION_GRANT",
|
|
3615
|
+
rawQuery: message.msg.text,
|
|
3616
|
+
sessionId: this._sessionId,
|
|
3617
|
+
userId: this._userId,
|
|
3618
|
+
isNewSession: false,
|
|
3619
|
+
granted: granted,
|
|
3620
|
+
userProfile: userProfile,
|
|
3621
|
+
intentId: "PermissionGrant",
|
|
3622
|
+
platform: "stentor-platform",
|
|
3623
|
+
channel: "widget",
|
|
3624
|
+
accessToken: accessToken,
|
|
3625
|
+
attributes: attributes
|
|
3626
|
+
};
|
|
3627
|
+
}
|
|
3628
|
+
else if (message.type === "custom") {
|
|
3629
|
+
request = __assign(__assign({}, JSON.parse(message.payload)), {
|
|
3630
|
+
// token: message.msg.token,
|
|
3631
|
+
sessionId: this._sessionId, userId: this._userId, isNewSession: false,
|
|
3632
|
+
// intentId: "OptionSelect",
|
|
3633
|
+
platform: "stentor-platform", channel: "widget", accessToken: accessToken, attributes: attributes });
|
|
3634
|
+
}
|
|
3635
|
+
else if (message.msg.token) {
|
|
3636
|
+
request = {
|
|
3637
|
+
type: "OPTION_SELECT_REQUEST",
|
|
3638
|
+
token: message.msg.token,
|
|
3639
|
+
sessionId: this._sessionId,
|
|
3640
|
+
userId: this._userId,
|
|
3641
|
+
isNewSession: false,
|
|
3642
|
+
intentId: "OptionSelect",
|
|
3643
|
+
platform: "stentor-platform",
|
|
3644
|
+
channel: "widget",
|
|
3645
|
+
accessToken: accessToken,
|
|
3646
|
+
attributes: attributes
|
|
3647
|
+
};
|
|
3648
|
+
}
|
|
3649
|
+
else {
|
|
3650
|
+
request = {
|
|
3651
|
+
type: "INTENT_REQUEST",
|
|
3652
|
+
rawQuery: message.msg.text,
|
|
3653
|
+
sessionId: this._sessionId,
|
|
3654
|
+
userId: this._userId,
|
|
3655
|
+
isNewSession: false,
|
|
3656
|
+
intentId: "NLU_RESULT_PLACEHOLDER",
|
|
3657
|
+
platform: "stentor-platform",
|
|
3658
|
+
channel: "widget",
|
|
3659
|
+
accessToken: accessToken,
|
|
3660
|
+
attributes: attributes
|
|
3661
|
+
};
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
return request;
|
|
3665
|
+
}
|
|
3666
|
+
function looksLikeEmail(email) {
|
|
3667
|
+
var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
3668
|
+
return re.test(String(email).toLowerCase());
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
/**
|
|
3672
|
+
* Converts a Stentor Request (from a widget) to a ChatMessageRequest
|
|
3673
|
+
*
|
|
3674
|
+
* it's text only - need to look into file exchange (this is widget-to-widget communication)
|
|
3675
|
+
*
|
|
3676
|
+
* @param botRequest
|
|
3677
|
+
* @param now
|
|
3678
|
+
* @returns
|
|
3679
|
+
*/
|
|
3680
|
+
function requestToMessage(botRequest, now) {
|
|
3681
|
+
if (now === void 0) { now = new Date().getTime(); }
|
|
3682
|
+
if (!botRequest) {
|
|
3683
|
+
return undefined;
|
|
3684
|
+
}
|
|
3685
|
+
var text = botRequest.rawQuery;
|
|
3686
|
+
var responseMessage = {
|
|
3687
|
+
type: "msg",
|
|
3688
|
+
timestamp: now,
|
|
3689
|
+
msg: {
|
|
3690
|
+
text: text,
|
|
3691
|
+
},
|
|
3692
|
+
endSession: false,
|
|
3693
|
+
user: undefined,
|
|
3694
|
+
};
|
|
3695
|
+
return responseMessage;
|
|
3696
|
+
}
|
|
3697
|
+
|
|
3698
|
+
var StentorRouterChat = /** @class */ (function () {
|
|
3699
|
+
function StentorRouterChat(config, options) {
|
|
3700
|
+
var _a;
|
|
3701
|
+
this._userId = "";
|
|
3702
|
+
this._sessionId = "";
|
|
3703
|
+
this.accessToken = "";
|
|
3704
|
+
this.attributes = {};
|
|
3705
|
+
this.isAdmin = false;
|
|
3706
|
+
this.urlAttributes = {};
|
|
3707
|
+
this.handlers = {};
|
|
3708
|
+
this.config = config;
|
|
3709
|
+
this.options = options;
|
|
3710
|
+
// Dig out the path parameters. Put them into the attributes.
|
|
3711
|
+
// The WS url is the barebone domain.
|
|
3712
|
+
var url = new URL(this.config.url);
|
|
3713
|
+
var urlPath = (_a = url.pathname) === null || _a === void 0 ? void 0 : _a.split("/");
|
|
3714
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3715
|
+
this.isAdmin = (url.searchParams.get('isAdmin') || window.xaIsAdmin) === "true";
|
|
3716
|
+
this.serverUrl = "".concat(url.origin);
|
|
3717
|
+
if (urlPath && urlPath.length > 1) {
|
|
3718
|
+
this.serverUrl = "".concat(this.serverUrl, "/").concat(urlPath[1]); // the first path (after the initial "") is the "dev" or "prod"
|
|
3719
|
+
this.urlAttributes.path = urlPath.slice(2);
|
|
3720
|
+
}
|
|
3721
|
+
log("WS url: ".concat(this.serverUrl, " attributes: ").concat(JSON.stringify(this.attributes)));
|
|
3722
|
+
// this.configurableMessages = options.configurableMessages;
|
|
3723
|
+
}
|
|
3724
|
+
StentorRouterChat.prototype.init = function (dispatch) {
|
|
3725
|
+
var _this = this;
|
|
3726
|
+
// Fire up the WebSocket
|
|
3727
|
+
this.autoReconnect(this.wsCreate.bind(this));
|
|
3728
|
+
this.dispatch = dispatch;
|
|
3729
|
+
// Register "handlers" for the incoming events
|
|
3730
|
+
this.handlers["account_status"] = function (_data, _sender) {
|
|
3731
|
+
// Register the "endpoint" with the server (send visitor data)
|
|
3732
|
+
_this.emit("connection update");
|
|
3733
|
+
dispatch({
|
|
3734
|
+
type: "account_status",
|
|
3735
|
+
detail: {
|
|
3736
|
+
status: "online",
|
|
3737
|
+
timestamp: +new Date(),
|
|
3738
|
+
},
|
|
3739
|
+
});
|
|
3740
|
+
};
|
|
3741
|
+
this.handlers["new message"] = function (data, sender) {
|
|
3742
|
+
// Because the router's internal message format is Stentor channel compatible.
|
|
3743
|
+
// So the data is either a stentor Request (from widget) or a stentor Response (from bot)
|
|
3744
|
+
var _a;
|
|
3745
|
+
var message;
|
|
3746
|
+
if (sender.deviceId === "Bot") {
|
|
3747
|
+
if (typeof ((_a = _this.options.hooks) === null || _a === void 0 ? void 0 : _a.onResponse) === "function") {
|
|
3748
|
+
_this.options.hooks.onResponse(message);
|
|
3749
|
+
}
|
|
3750
|
+
message = responseToMessage(data);
|
|
3751
|
+
}
|
|
3752
|
+
else if (sender.deviceId === "Widget") {
|
|
3753
|
+
message = requestToMessage(data);
|
|
3754
|
+
}
|
|
3755
|
+
else {
|
|
3756
|
+
err("Unknown sender device Id: ".concat(sender.deviceId));
|
|
3757
|
+
}
|
|
3758
|
+
_this.dispatch({
|
|
3759
|
+
type: "chat",
|
|
3760
|
+
detail: {
|
|
3761
|
+
type: "chat.msg",
|
|
3762
|
+
user: {
|
|
3763
|
+
displayName: sender.displayName || sender.email || sender.userId,
|
|
3764
|
+
nick: senderToNick(sender),
|
|
3765
|
+
},
|
|
3766
|
+
msg: message,
|
|
3767
|
+
timestamp: +new Date(),
|
|
3768
|
+
},
|
|
3769
|
+
});
|
|
3770
|
+
};
|
|
3771
|
+
this.handlers["user joined"] = function (_data, sender) {
|
|
3772
|
+
_this.dispatch({
|
|
3773
|
+
type: "chat",
|
|
3774
|
+
detail: {
|
|
3775
|
+
type: "chat.memberjoin",
|
|
3776
|
+
user: {
|
|
3777
|
+
displayName: sender.displayName,
|
|
3778
|
+
nick: senderToNick(sender),
|
|
3779
|
+
avatarPath: sender.avatarPath,
|
|
3780
|
+
},
|
|
3781
|
+
timestamp: +new Date(),
|
|
3782
|
+
},
|
|
3783
|
+
});
|
|
3784
|
+
};
|
|
3785
|
+
this.handlers["user left"] = function (_data, sender) {
|
|
3786
|
+
_this.dispatch({
|
|
3787
|
+
type: "chat",
|
|
3788
|
+
detail: {
|
|
3789
|
+
type: "chat.memberleave",
|
|
3790
|
+
user: {
|
|
3791
|
+
displayName: sender.displayName,
|
|
3792
|
+
nick: senderToNick(sender),
|
|
3793
|
+
},
|
|
3794
|
+
timestamp: +new Date(),
|
|
3795
|
+
},
|
|
3796
|
+
});
|
|
3797
|
+
};
|
|
3798
|
+
this.handlers["typing"] = function (_data, sender) {
|
|
3799
|
+
_this.dispatch({
|
|
3800
|
+
type: "chat",
|
|
3801
|
+
detail: {
|
|
3802
|
+
type: "chat.typing",
|
|
3803
|
+
user: {
|
|
3804
|
+
nick: senderToNick(sender),
|
|
3805
|
+
},
|
|
3806
|
+
typing: true,
|
|
3807
|
+
timestamp: +new Date(),
|
|
3808
|
+
},
|
|
3809
|
+
});
|
|
3810
|
+
};
|
|
3811
|
+
this.handlers["stop typing"] = function (_data, sender) {
|
|
3812
|
+
_this.dispatch({
|
|
3813
|
+
type: "chat",
|
|
3814
|
+
detail: {
|
|
3815
|
+
type: "chat.typing",
|
|
3816
|
+
user: {
|
|
3817
|
+
nick: senderToNick(sender),
|
|
3818
|
+
},
|
|
3819
|
+
typing: false,
|
|
3820
|
+
timestamp: +new Date(),
|
|
3821
|
+
},
|
|
3822
|
+
});
|
|
3823
|
+
};
|
|
3824
|
+
this.handlers["disconnect"] = function () {
|
|
3825
|
+
_this.dispatch(setAccountStatus("offline"));
|
|
3826
|
+
_this.dispatch(setConnectionStatus("offline"));
|
|
3827
|
+
};
|
|
3828
|
+
this.handlers["reconnect"] = function () {
|
|
3829
|
+
_this.dispatch(setAccountStatus("online"));
|
|
3830
|
+
_this.dispatch(setConnectionStatus("online"));
|
|
3831
|
+
};
|
|
3832
|
+
this.handlers["reconnect_failed"] = function (_data) {
|
|
3833
|
+
_this.dispatch(setAccountStatus("offline"));
|
|
3834
|
+
_this.dispatch(setConnectionStatus("offline"));
|
|
3835
|
+
};
|
|
3836
|
+
this.handlers["reconnect_error"] = function (_data) {
|
|
3837
|
+
_this.dispatch(setAccountStatus("offline"));
|
|
3838
|
+
};
|
|
3839
|
+
this.setAccountStatus("offline");
|
|
3840
|
+
};
|
|
3841
|
+
StentorRouterChat.prototype.autoReconnect = function (wsCreate) {
|
|
3842
|
+
var _this = this;
|
|
3843
|
+
var setStatus = this.setAccountStatus.bind(this);
|
|
3844
|
+
function startReconnecting() {
|
|
3845
|
+
setStatus("offline");
|
|
3846
|
+
var interval = setInterval(function () {
|
|
3847
|
+
log("Re-creating WS connection");
|
|
3848
|
+
var ws = wsCreate();
|
|
3849
|
+
ws.onopen = function () {
|
|
3850
|
+
log("Re-opened WS connection");
|
|
3851
|
+
// We are connected
|
|
3852
|
+
setStatus("online");
|
|
3853
|
+
ws.onclose = startReconnecting;
|
|
3854
|
+
clearInterval(interval);
|
|
3855
|
+
};
|
|
3856
|
+
}, 3000);
|
|
3857
|
+
}
|
|
3858
|
+
log("Creating WS connection");
|
|
3859
|
+
wsCreate();
|
|
3860
|
+
this.ws.onclose = startReconnecting;
|
|
3861
|
+
this.ws.onopen = function () {
|
|
3862
|
+
log("Opened WS connection");
|
|
3863
|
+
// We are connected
|
|
3864
|
+
_this.setAccountStatus("online");
|
|
3865
|
+
};
|
|
3866
|
+
};
|
|
3867
|
+
StentorRouterChat.prototype.wsCreate = function () {
|
|
3868
|
+
this.ws = new WebSocket("".concat(this.serverUrl, "?userId=").concat(this._userId));
|
|
3869
|
+
this.ws.onmessage = function (data) {
|
|
3870
|
+
console.log("SERVER says: ".concat(JSON.stringify(data)));
|
|
3871
|
+
// const message: RouterMessage = JSON.parse(data);
|
|
3872
|
+
// this.handlers[message.event](message.data, message.sender);
|
|
3873
|
+
};
|
|
3874
|
+
return this.ws;
|
|
3875
|
+
};
|
|
3876
|
+
StentorRouterChat.prototype.emit = function (event, data) {
|
|
3877
|
+
var payloadData = JSON.stringify({ event: event, data: data, sender: this.visitorInfo });
|
|
3878
|
+
log("Widget says: ".concat(payloadData));
|
|
3879
|
+
this.ws.send(payloadData);
|
|
3880
|
+
};
|
|
3881
|
+
StentorRouterChat.prototype.setAccountStatus = function (status) {
|
|
3882
|
+
log("SERVER account_status: ".concat(JSON.stringify(status)));
|
|
3883
|
+
this.dispatch(setAccountStatus(status));
|
|
3884
|
+
};
|
|
3885
|
+
StentorRouterChat.prototype.sendOfflineMsg = function (_, cb) {
|
|
3886
|
+
cb();
|
|
3887
|
+
};
|
|
3888
|
+
StentorRouterChat.prototype.sendChatMsg = function (message, cb) {
|
|
3889
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
3890
|
+
return __generator$1(this, function (_a) {
|
|
3891
|
+
return [2 /*return*/, this.sendChatMsgRequest({
|
|
3892
|
+
msg: message,
|
|
3893
|
+
timestamp: new Date().getTime(),
|
|
3894
|
+
agent: false,
|
|
3895
|
+
user: undefined,
|
|
3896
|
+
type: "msg",
|
|
3897
|
+
}, cb)];
|
|
3898
|
+
});
|
|
3899
|
+
});
|
|
3900
|
+
};
|
|
3901
|
+
StentorRouterChat.prototype.sendChatMsgRequest = function (serviceRequest, cb) {
|
|
3902
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
3903
|
+
return __generator$1(this, function (_a) {
|
|
3904
|
+
switch (_a.label) {
|
|
3905
|
+
case 0: return [4 /*yield*/, this.postMessage(serviceRequest)];
|
|
3906
|
+
case 1:
|
|
3907
|
+
_a.sent();
|
|
3908
|
+
cb();
|
|
3909
|
+
return [2 /*return*/];
|
|
3910
|
+
}
|
|
3911
|
+
});
|
|
3912
|
+
});
|
|
3913
|
+
};
|
|
3914
|
+
StentorRouterChat.prototype.sendTyping = function (isTyping) {
|
|
3915
|
+
this.emit(isTyping ? "typing" : "stop typing");
|
|
3916
|
+
};
|
|
3917
|
+
StentorRouterChat.prototype.setVisitorInfo = function (visitorInfoMessage, cb) {
|
|
3918
|
+
log("Visitor Info Mesage = ".concat(visitorInfoMessage));
|
|
3919
|
+
this.visitorInfo = {
|
|
3920
|
+
deviceId: "Widget",
|
|
3921
|
+
userId: visitorInfoMessage.userId,
|
|
3922
|
+
displayName: visitorInfoMessage.displayName || visitorInfoMessage.name,
|
|
3923
|
+
email: visitorInfoMessage.email,
|
|
3924
|
+
isAdmin: this.isAdmin,
|
|
3925
|
+
urlAttributes: this.urlAttributes
|
|
3926
|
+
};
|
|
3927
|
+
this.attributes = __assign(__assign(__assign({}, visitorInfoMessage.attributes), this.attributes), { currentUrl: window.location.href });
|
|
3928
|
+
this.accessToken = visitorInfoMessage.accessToken;
|
|
3929
|
+
this.emit("add user");
|
|
3930
|
+
this.startSession();
|
|
3931
|
+
cb();
|
|
3932
|
+
};
|
|
3933
|
+
StentorRouterChat.prototype.sendChatRating = function () { };
|
|
3934
|
+
StentorRouterChat.prototype.sendFile = function (_, cb) {
|
|
3935
|
+
cb();
|
|
3936
|
+
};
|
|
3937
|
+
StentorRouterChat.prototype.markAsRead = function () {
|
|
3938
|
+
// mark the messages read
|
|
3939
|
+
};
|
|
3940
|
+
StentorRouterChat.prototype.flush = function () { };
|
|
3941
|
+
StentorRouterChat.prototype.dispose = function () { };
|
|
3942
|
+
StentorRouterChat.prototype.postMessage = function (message) {
|
|
3943
|
+
return __awaiter$1(this, void 0, void 0, function () {
|
|
3944
|
+
var userId, sessionId, accessToken, attributes, request;
|
|
3945
|
+
return __generator$1(this, function (_a) {
|
|
3946
|
+
userId = this._userId;
|
|
3947
|
+
sessionId = this._sessionId;
|
|
3948
|
+
accessToken = this.accessToken;
|
|
3949
|
+
attributes = this.attributes || {};
|
|
3950
|
+
request = requestFromMessage(message, userId, this.isNewSession, sessionId, accessToken, attributes);
|
|
3951
|
+
this.emit("new message", request);
|
|
3952
|
+
return [2 /*return*/];
|
|
3953
|
+
});
|
|
3954
|
+
});
|
|
3955
|
+
};
|
|
3956
|
+
StentorRouterChat.prototype.startSession = function () {
|
|
3957
|
+
if (this.visitorInfo.userId) {
|
|
3958
|
+
this._userId = "".concat(this.visitorInfo.userId);
|
|
3959
|
+
}
|
|
3960
|
+
else if (this.visitorInfo.email) {
|
|
3961
|
+
this._userId = "stentor-widget-user-".concat(this.visitorInfo.email);
|
|
3962
|
+
}
|
|
3963
|
+
else {
|
|
3964
|
+
this._userId = "stentor-widget-user-".concat(uuid_1());
|
|
3965
|
+
}
|
|
3966
|
+
if (get("sessionId") !== "") {
|
|
3967
|
+
this._sessionId = get("sessionId");
|
|
3968
|
+
}
|
|
3969
|
+
else {
|
|
3970
|
+
this._sessionId = "stentor-widget-session-".concat(uuid_1());
|
|
3971
|
+
set$1("sessionId", this._sessionId);
|
|
3972
|
+
}
|
|
3973
|
+
// This is a flag that is cleared after the first message is sent
|
|
3974
|
+
this.isNewSession = true;
|
|
3975
|
+
};
|
|
3976
|
+
Object.defineProperty(StentorRouterChat.prototype, "userId", {
|
|
3977
|
+
get: function () {
|
|
3978
|
+
return this._userId;
|
|
3979
|
+
},
|
|
3980
|
+
enumerable: false,
|
|
3981
|
+
configurable: true
|
|
3982
|
+
});
|
|
3983
|
+
Object.defineProperty(StentorRouterChat.prototype, "sessionId", {
|
|
3984
|
+
get: function () {
|
|
3985
|
+
return this._sessionId;
|
|
3986
|
+
},
|
|
3987
|
+
enumerable: false,
|
|
3988
|
+
configurable: true
|
|
3989
|
+
});
|
|
3990
|
+
return StentorRouterChat;
|
|
3991
|
+
}());
|
|
3992
|
+
function senderToNick(sender) {
|
|
3993
|
+
return "".concat(sender.deviceId, "-").concat(sender.userId);
|
|
3994
|
+
}
|
|
3995
|
+
|
|
3555
3996
|
const PACKET_TYPES = Object.create(null); // no Map = no polyfill
|
|
3556
3997
|
PACKET_TYPES["open"] = "0";
|
|
3557
3998
|
PACKET_TYPES["close"] = "1";
|
|
@@ -4565,7 +5006,7 @@ const nextTick = (() => {
|
|
|
4565
5006
|
return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
|
|
4566
5007
|
}
|
|
4567
5008
|
})();
|
|
4568
|
-
const WebSocket = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
5009
|
+
const WebSocket$1 = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
4569
5010
|
const usingBrowserWebSocket = true;
|
|
4570
5011
|
const defaultBinaryType = "arraybuffer";
|
|
4571
5012
|
|
|
@@ -4615,9 +5056,9 @@ class WS extends Transport {
|
|
|
4615
5056
|
this.ws =
|
|
4616
5057
|
usingBrowserWebSocket && !isReactNative
|
|
4617
5058
|
? protocols
|
|
4618
|
-
? new WebSocket(uri, protocols)
|
|
4619
|
-
: new WebSocket(uri)
|
|
4620
|
-
: new WebSocket(uri, protocols, opts);
|
|
5059
|
+
? new WebSocket$1(uri, protocols)
|
|
5060
|
+
: new WebSocket$1(uri)
|
|
5061
|
+
: new WebSocket$1(uri, protocols, opts);
|
|
4621
5062
|
}
|
|
4622
5063
|
catch (err) {
|
|
4623
5064
|
return this.emitReserved("error", err);
|
|
@@ -4732,7 +5173,7 @@ class WS extends Transport {
|
|
|
4732
5173
|
* @api public
|
|
4733
5174
|
*/
|
|
4734
5175
|
check() {
|
|
4735
|
-
return !!WebSocket;
|
|
5176
|
+
return !!WebSocket$1;
|
|
4736
5177
|
}
|
|
4737
5178
|
}
|
|
4738
5179
|
|
|
@@ -6927,6 +7368,7 @@ var StentorServerChat = /** @class */ (function () {
|
|
|
6927
7368
|
}
|
|
6928
7369
|
});
|
|
6929
7370
|
});
|
|
7371
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6930
7372
|
this.socket.on("new message", function (data) {
|
|
6931
7373
|
log("SERVER: new message: ".concat(JSON.stringify(data)));
|
|
6932
7374
|
_this.dispatch({
|
|
@@ -6942,6 +7384,7 @@ var StentorServerChat = /** @class */ (function () {
|
|
|
6942
7384
|
}
|
|
6943
7385
|
});
|
|
6944
7386
|
});
|
|
7387
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6945
7388
|
this.socket.on("user joined", function (data) {
|
|
6946
7389
|
log("SERVER: user joined: ".concat(JSON.stringify(data)));
|
|
6947
7390
|
_this.visitorInfo.token = data.token;
|
|
@@ -6958,6 +7401,7 @@ var StentorServerChat = /** @class */ (function () {
|
|
|
6958
7401
|
}
|
|
6959
7402
|
});
|
|
6960
7403
|
});
|
|
7404
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6961
7405
|
this.socket.on("user left", function (data) {
|
|
6962
7406
|
log("SERVER: user left: ".concat(JSON.stringify(data)));
|
|
6963
7407
|
_this.dispatch({
|
|
@@ -6986,6 +7430,7 @@ var StentorServerChat = /** @class */ (function () {
|
|
|
6986
7430
|
}
|
|
6987
7431
|
});
|
|
6988
7432
|
});
|
|
7433
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6989
7434
|
this.socket.on("stop typing", function (data) {
|
|
6990
7435
|
log("SERVER: stop typing: ".concat(JSON.stringify(data)));
|
|
6991
7436
|
_this.dispatch({
|
|
@@ -7067,6 +7512,10 @@ function createChatServerCore(config, options) {
|
|
|
7067
7512
|
return new StentorServerChat({
|
|
7068
7513
|
url: config.serverUrl
|
|
7069
7514
|
}, options);
|
|
7515
|
+
case "websocketraw":
|
|
7516
|
+
return new StentorRouterChat({
|
|
7517
|
+
url: config.serverUrl
|
|
7518
|
+
}, options);
|
|
7070
7519
|
case "local":
|
|
7071
7520
|
return new StentorLocalChat();
|
|
7072
7521
|
default:
|
|
@@ -31164,6 +31613,7 @@ var ChatWidget = function (props) {
|
|
|
31164
31613
|
if (checkSessionExpiration(chatState === null || chatState === void 0 ? void 0 : chatState.sessionExpiration, (_a = chatState === null || chatState === void 0 ? void 0 : chatState.chats[chatState.chats.length - 1]) === null || _a === void 0 ? void 0 : _a.timestamp, chatState === null || chatState === void 0 ? void 0 : chatState.lastTimestamp)) {
|
|
31165
31614
|
innerDispatch(reset());
|
|
31166
31615
|
}
|
|
31616
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31167
31617
|
}, []);
|
|
31168
31618
|
React$1.useEffect(function () {
|
|
31169
31619
|
// For reopen widget after move on same windowyar
|
|
@@ -31573,7 +32023,7 @@ function mapSynthetic(state, action) {
|
|
|
31573
32023
|
}
|
|
31574
32024
|
};
|
|
31575
32025
|
default:
|
|
31576
|
-
throw new Error("Unknown synthetic action. Detail type: ".concat(action.detail.type));
|
|
32026
|
+
throw new Error("Unknown synthetic action. Detail type: ".concat((action.detail).type));
|
|
31577
32027
|
}
|
|
31578
32028
|
}
|
|
31579
32029
|
function storeHandler(state, action) {
|
|
@@ -31609,6 +32059,7 @@ function createChatStore(config, dataStorage) {
|
|
|
31609
32059
|
var middlewares = [
|
|
31610
32060
|
thunk__default["default"]
|
|
31611
32061
|
];
|
|
32062
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31612
32063
|
var composeEnhancers = globalThis.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || redux.compose;
|
|
31613
32064
|
return redux.createStore(chatReducer, composeEnhancers(redux.applyMiddleware.apply(void 0, middlewares)));
|
|
31614
32065
|
}
|
|
@@ -31642,6 +32093,7 @@ function createStaticReducer(state) {
|
|
|
31642
32093
|
return oldState;
|
|
31643
32094
|
};
|
|
31644
32095
|
}
|
|
32096
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31645
32097
|
var composeEnhancers = (globalThis === null || globalThis === void 0 ? void 0 : globalThis.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || redux.compose;
|
|
31646
32098
|
var middlewares = [
|
|
31647
32099
|
thunk__default["default"]
|