@xapp/chat-widget 1.32.1 → 1.35.0-alpha.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/components/Avatar/Avatar.d.ts +2 -2
- package/dist/components/ChatMessage/ChatMessage.d.ts +2 -2
- package/dist/components/ChatMessagePart/ChatMessagePart.d.ts +2 -2
- package/dist/components/ChatRating/ChatRating.d.ts +2 -2
- package/dist/components/ChatRating/ChatRatingContainer.d.ts +2 -2
- package/dist/components/StatusContainer/StatusContainer.d.ts +2 -2
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +176 -140
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +176 -140
- package/dist/index.js.map +1 -1
- package/dist/middlewares/message-middleware.d.ts +2 -2
- package/dist/middlewares/middleware-ctx-factory.d.ts +2 -2
- package/dist/store/ChatAction.d.ts +3 -3
- package/dist/store/ChatState.d.ts +3 -3
- package/dist/store/actions/writeMessage.d.ts +2 -2
- package/dist/utils/index.d.ts +4 -3
- package/dist/xapp/ChatServer.d.ts +5 -0
- package/dist/xapp/ChatServerMessage.d.ts +2 -2
- package/dist/xapp/StentorDirectChat.d.ts +10 -5
- package/dist/xapp/StentorServerChat.d.ts +4 -5
- package/dist/xapp/UserInfo.d.ts +2 -4
- package/dist/xapp/XappChat.d.ts +3 -3
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1475,7 +1475,7 @@ var logOnce = function (key) {
|
|
|
1475
1475
|
var map = {};
|
|
1476
1476
|
if (!map[key]) {
|
|
1477
1477
|
map[key] = true;
|
|
1478
|
-
log(args);
|
|
1478
|
+
log.apply(void 0, args);
|
|
1479
1479
|
}
|
|
1480
1480
|
};
|
|
1481
1481
|
|
|
@@ -2157,16 +2157,25 @@ var RichTextBoldSpan = function (props) {
|
|
|
2157
2157
|
};
|
|
2158
2158
|
|
|
2159
2159
|
var RichTextInputSpan = function (props) {
|
|
2160
|
-
var format = props.format, text = props.text, readOnly = props.readOnly;
|
|
2160
|
+
var format = props.format, text = props.text, readOnly = props.readOnly, onClick = props.onClick;
|
|
2161
2161
|
var defaultValue = format.text || text.substring(format.start, format.end);
|
|
2162
2162
|
var _a = React.useState(defaultValue), value = _a[0], setValue = _a[1];
|
|
2163
2163
|
var handleChange = React.useCallback(function (ev) {
|
|
2164
2164
|
setValue(ev.target.value);
|
|
2165
2165
|
}, []);
|
|
2166
|
+
var handleClick = React.useCallback(function (ev) {
|
|
2167
|
+
if (onClick) {
|
|
2168
|
+
var res = onClick(format);
|
|
2169
|
+
if (res === false) {
|
|
2170
|
+
ev.preventDefault();
|
|
2171
|
+
ev.stopPropagation();
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
}, [onClick, format]);
|
|
2166
2175
|
if (readOnly) {
|
|
2167
|
-
return (React__default["default"].createElement("span", { className: "xapp-search-rich-text-input-span xapp-search-rich-text-input-span--readonly" }, defaultValue));
|
|
2176
|
+
return (React__default["default"].createElement("span", { className: "xapp-search-rich-text-input-span xapp-search-rich-text-input-span--readonly", onClick: handleClick }, defaultValue));
|
|
2168
2177
|
}
|
|
2169
|
-
return (React__default["default"].createElement("input", { type: "text", value: value, className: "xapp-search-rich-text-input-span", "data-rich-text-type": "inputText", onChange: handleChange, readOnly: readOnly }));
|
|
2178
|
+
return (React__default["default"].createElement("input", { type: "text", value: value, className: "xapp-search-rich-text-input-span", "data-rich-text-type": "inputText", onChange: handleChange, onClick: handleClick, readOnly: readOnly }));
|
|
2170
2179
|
};
|
|
2171
2180
|
|
|
2172
2181
|
var RichTextNormalSpan = function (props) {
|
|
@@ -2175,7 +2184,7 @@ var RichTextNormalSpan = function (props) {
|
|
|
2175
2184
|
};
|
|
2176
2185
|
|
|
2177
2186
|
var RichTextSpan = function (props) {
|
|
2178
|
-
var format = props.format, text = props.text, readOnly = props.readOnly;
|
|
2187
|
+
var format = props.format, text = props.text, readOnly = props.readOnly, onClick = props.onClick;
|
|
2179
2188
|
var type = format.type;
|
|
2180
2189
|
switch (type) {
|
|
2181
2190
|
case "normal":
|
|
@@ -2183,7 +2192,7 @@ var RichTextSpan = function (props) {
|
|
|
2183
2192
|
case "bold":
|
|
2184
2193
|
return (React__default["default"].createElement(RichTextBoldSpan, { text: text, format: format, readOnly: readOnly }));
|
|
2185
2194
|
case "inputText":
|
|
2186
|
-
return (React__default["default"].createElement(RichTextInputSpan, { text: text, format: format, readOnly: readOnly }));
|
|
2195
|
+
return (React__default["default"].createElement(RichTextInputSpan, { text: text, format: format, readOnly: readOnly, onClick: onClick }));
|
|
2187
2196
|
default:
|
|
2188
2197
|
throwBadKind(type);
|
|
2189
2198
|
}
|
|
@@ -2310,7 +2319,7 @@ function cleanContent(node) {
|
|
|
2310
2319
|
}
|
|
2311
2320
|
}
|
|
2312
2321
|
var RichText = function (props) {
|
|
2313
|
-
var value = props.value, className = props.className, readOnly = props.readOnly, onInput = props.onInput, onChange = props.onChange;
|
|
2322
|
+
var value = props.value, className = props.className, readOnly = props.readOnly, onInput = props.onInput, onChange = props.onChange, onSpanClick = props.onSpanClick;
|
|
2314
2323
|
var formatsRaw = value.formats, text = value.text;
|
|
2315
2324
|
var formats = React.useMemo(function () { return extendFormat(formatsRaw, text.length); }, [formatsRaw, text.length]);
|
|
2316
2325
|
var handleInput = React.useCallback(function (ev) {
|
|
@@ -2328,7 +2337,7 @@ var RichText = function (props) {
|
|
|
2328
2337
|
onChange(newValue);
|
|
2329
2338
|
}
|
|
2330
2339
|
}, [onChange]);
|
|
2331
|
-
return (React__default["default"].createElement("div", { id: props.id, className: "xapp-search-rich-text ".concat(className || ""), contentEditable: !readOnly, suppressContentEditableWarning: true, onInput: handleInput, onBlur: handleBlur }, formats.map(function (format, index) { return (React__default["default"].createElement(RichTextSpan, { format: format, text: text,
|
|
2340
|
+
return (React__default["default"].createElement("div", { id: props.id, className: "xapp-search-rich-text ".concat(className || ""), contentEditable: !readOnly, suppressContentEditableWarning: true, onInput: handleInput, onBlur: handleBlur, onKeyDown: props.onKeyDown }, formats.map(function (format, index) { return (React__default["default"].createElement(RichTextSpan, { key: index, format: format, text: text, readOnly: readOnly, onClick: onSpanClick })); })));
|
|
2332
2341
|
};
|
|
2333
2342
|
|
|
2334
2343
|
var RichInput = function (props) {
|
|
@@ -2382,7 +2391,7 @@ var RichInput = function (props) {
|
|
|
2382
2391
|
return undefined;
|
|
2383
2392
|
}, [inputNode, onSearch]);
|
|
2384
2393
|
return (React__default["default"].createElement("div", { className: "xappw-rich-input ".concat(props.className) }, rich ?
|
|
2385
|
-
React__default["default"].createElement(RichText, { id: id, value: value, onChange: handleRichChange, onInput: handleRichInput, className: "xappw-rich-input__input ".concat(props.className, "__input") }) : React__default["default"].createElement("input", { id: id, ref: inputRef, type: type, value: value.text, autoFocus: autoFocus, placeholder: props.placeholder, className: "xappw-rich-input__input ".concat(props.className, "__input"), onFocus: props.onFocus, onChange: handleChange, onInput: handleInput, onKeyDown: handleKeyDown })));
|
|
2394
|
+
React__default["default"].createElement(RichText, { id: id, value: value, onChange: handleRichChange, onInput: handleRichInput, onKeyDown: handleKeyDown, className: "xappw-rich-input__input ".concat(props.className, "__input") }) : React__default["default"].createElement("input", { id: id, ref: inputRef, type: type, value: value.text, autoFocus: autoFocus, placeholder: props.placeholder, className: "xappw-rich-input__input ".concat(props.className, "__input"), onFocus: props.onFocus, onChange: handleChange, onInput: handleInput, onKeyDown: handleKeyDown })));
|
|
2386
2395
|
};
|
|
2387
2396
|
|
|
2388
2397
|
var SuggestionsGroupHeading = function (props) {
|
|
@@ -2397,7 +2406,7 @@ function getScrollContainer(node) {
|
|
|
2397
2406
|
return walker || undefined;
|
|
2398
2407
|
}
|
|
2399
2408
|
var SuggestionsItem = function (props) {
|
|
2400
|
-
var data = props.data, current = props.current, ActionsComponent = props.actions, onClick = props.onClick, onHover = props.onHover;
|
|
2409
|
+
var data = props.data, current = props.current, ActionsComponent = props.actions, onClick = props.onClick, onHover = props.onHover, onSpanClick = props.onSpanClick;
|
|
2401
2410
|
var handleClick = React.useCallback(function () {
|
|
2402
2411
|
onClick(data);
|
|
2403
2412
|
}, [data, onClick]);
|
|
@@ -2406,6 +2415,12 @@ var SuggestionsItem = function (props) {
|
|
|
2406
2415
|
onHover(data);
|
|
2407
2416
|
}
|
|
2408
2417
|
}, [data, onHover]);
|
|
2418
|
+
var handleSpanClick = React.useCallback(function (span) {
|
|
2419
|
+
if (onSpanClick) {
|
|
2420
|
+
return onSpanClick(data, span);
|
|
2421
|
+
}
|
|
2422
|
+
return undefined;
|
|
2423
|
+
}, [onSpanClick, data]);
|
|
2409
2424
|
var ref = React.useRef(null);
|
|
2410
2425
|
React.useEffect(function () {
|
|
2411
2426
|
var node = ref.current;
|
|
@@ -2425,7 +2440,7 @@ var SuggestionsItem = function (props) {
|
|
|
2425
2440
|
}
|
|
2426
2441
|
}, [current]);
|
|
2427
2442
|
return (React__default["default"].createElement("div", { ref: ref, className: "xappw-suggestions-item ".concat(current ? "xappw-suggestions-item--current" : ""), onClick: handleClick, onMouseEnter: handleHover },
|
|
2428
|
-
React__default["default"].createElement(RichText, { value: data, className: "xappw-suggestions-item__texts", readOnly: true }),
|
|
2443
|
+
React__default["default"].createElement(RichText, { value: data, className: "xappw-suggestions-item__texts", readOnly: true, onSpanClick: handleSpanClick }),
|
|
2429
2444
|
ActionsComponent &&
|
|
2430
2445
|
React__default["default"].createElement("div", { className: "xappw-suggestions-item__actions" },
|
|
2431
2446
|
React__default["default"].createElement(ActionsComponent, { data: data, current: current }))));
|
|
@@ -2438,7 +2453,7 @@ var SuggestionsGroup = function (props) {
|
|
|
2438
2453
|
React__default["default"].createElement("div", { className: "xappw-suggestions-group__heading" },
|
|
2439
2454
|
React__default["default"].createElement(SuggestionsGroupHeading, { label: heading })),
|
|
2440
2455
|
React__default["default"].createElement("div", { className: "xappw-suggestions-group__items" }, items.map(function (item, itemIndex) {
|
|
2441
|
-
return React__default["default"].createElement(SuggestionsItem, { key: itemIndex, data: item, current: currentIndex === itemIndex, actions: itemActions, onClick: props.onItemClick, onHover: props.onItemHover });
|
|
2456
|
+
return React__default["default"].createElement(SuggestionsItem, { key: itemIndex, data: item, current: currentIndex === itemIndex, actions: itemActions, onClick: props.onItemClick, onHover: props.onItemHover, onSpanClick: props.onSpanClick });
|
|
2442
2457
|
}))));
|
|
2443
2458
|
};
|
|
2444
2459
|
|
|
@@ -2452,7 +2467,7 @@ var SuggestionsList = function (props) {
|
|
|
2452
2467
|
var currentIndex = length >= 0 ? props.index : NaN;
|
|
2453
2468
|
var indexWalker = 0;
|
|
2454
2469
|
return (React__default["default"].createElement("div", { className: "xappw-suggestions-list ".concat(className || "") }, suggestions.map(function (group, index) {
|
|
2455
|
-
var res = (React__default["default"].createElement(SuggestionsGroup, { key: index, group: group, currentIndex: currentIndex - indexWalker, itemActions: itemActions, onItemClick: props.onItemClick, onItemHover: props.onItemHover }));
|
|
2470
|
+
var res = (React__default["default"].createElement(SuggestionsGroup, { key: index, group: group, currentIndex: currentIndex - indexWalker, itemActions: itemActions, onItemClick: props.onItemClick, onItemHover: props.onItemHover, onSpanClick: props.onSpanClick }));
|
|
2456
2471
|
indexWalker += group.items.length;
|
|
2457
2472
|
return res;
|
|
2458
2473
|
})));
|
|
@@ -2947,115 +2962,111 @@ function getPermissionResponse(botResponse, now) {
|
|
|
2947
2962
|
}
|
|
2948
2963
|
|
|
2949
2964
|
var PERMISSION_QUESTION_EXPIRATION_MS = 300000; // 5 minutes
|
|
2965
|
+
// interface UserLeaveMessage {
|
|
2966
|
+
// readonly user: ChatUserInfo;
|
|
2967
|
+
// readonly token: string; //todo: what is this
|
|
2968
|
+
// }
|
|
2950
2969
|
var StentorDirectChat = /** @class */ (function () {
|
|
2951
|
-
function StentorDirectChat(config) {
|
|
2952
|
-
var _this = this;
|
|
2970
|
+
function StentorDirectChat(config, options) {
|
|
2953
2971
|
this._userId = "";
|
|
2954
2972
|
this._sessionId = "";
|
|
2955
|
-
/*
|
|
2956
|
-
* FROM STENTOR TO WIDGET
|
|
2957
|
-
*/
|
|
2958
|
-
this.widget = {
|
|
2959
|
-
setConnectionStatus: function (status) {
|
|
2960
|
-
log("SERVER: connection_update: ".concat(JSON.stringify(status)));
|
|
2961
|
-
_this.dispatch(setConnectionStatus(status));
|
|
2962
|
-
},
|
|
2963
|
-
setAccountStatus: function (status) {
|
|
2964
|
-
log("SERVER: account_status: ".concat(JSON.stringify(status)));
|
|
2965
|
-
_this.dispatch(setAccountStatus(status));
|
|
2966
|
-
},
|
|
2967
|
-
sendNewMessage: function (data) {
|
|
2968
|
-
log("SERVER: new message: ".concat(JSON.stringify(data)));
|
|
2969
|
-
_this.dispatch({
|
|
2970
|
-
type: "chat",
|
|
2971
|
-
detail: {
|
|
2972
|
-
type: "chat.msg",
|
|
2973
|
-
user: __assign(__assign({}, data.user), { nick: "agent:robot" }),
|
|
2974
|
-
msg: data.msg,
|
|
2975
|
-
timestamp: +new Date()
|
|
2976
|
-
}
|
|
2977
|
-
});
|
|
2978
|
-
},
|
|
2979
|
-
userJoined: function (data) {
|
|
2980
|
-
log("SERVER: user joined: ".concat(JSON.stringify(data)));
|
|
2981
|
-
_this.visitorInfo.token = data.token;
|
|
2982
|
-
_this.dispatch({
|
|
2983
|
-
type: "chat",
|
|
2984
|
-
detail: {
|
|
2985
|
-
type: "chat.memberjoin",
|
|
2986
|
-
user: __assign(__assign({}, data.user), { nick: "agent:robot" }),
|
|
2987
|
-
timestamp: +new Date(),
|
|
2988
|
-
}
|
|
2989
|
-
});
|
|
2990
|
-
},
|
|
2991
|
-
userLeft: function (data) {
|
|
2992
|
-
log("SERVER: user left: ".concat(JSON.stringify(data)));
|
|
2993
|
-
_this.dispatch({
|
|
2994
|
-
type: "chat",
|
|
2995
|
-
detail: {
|
|
2996
|
-
type: "chat.memberleave",
|
|
2997
|
-
user: __assign(__assign({}, data.user), { nick: "agent:robot" }),
|
|
2998
|
-
timestamp: +new Date()
|
|
2999
|
-
}
|
|
3000
|
-
});
|
|
3001
|
-
},
|
|
3002
|
-
typing: function () {
|
|
3003
|
-
_this.dispatch({
|
|
3004
|
-
type: "chat",
|
|
3005
|
-
detail: {
|
|
3006
|
-
type: "chat.typing",
|
|
3007
|
-
user: {
|
|
3008
|
-
nick: "agent:robot",
|
|
3009
|
-
},
|
|
3010
|
-
typing: true,
|
|
3011
|
-
timestamp: +new Date()
|
|
3012
|
-
}
|
|
3013
|
-
});
|
|
3014
|
-
},
|
|
3015
|
-
stopTyping: function () {
|
|
3016
|
-
_this.dispatch({
|
|
3017
|
-
type: "chat",
|
|
3018
|
-
detail: {
|
|
3019
|
-
type: "chat.typing",
|
|
3020
|
-
user: {
|
|
3021
|
-
nick: "agent:robot",
|
|
3022
|
-
},
|
|
3023
|
-
typing: false,
|
|
3024
|
-
timestamp: +new Date()
|
|
3025
|
-
}
|
|
3026
|
-
});
|
|
3027
|
-
},
|
|
3028
|
-
disconnect: function () {
|
|
3029
|
-
log("SERVER: disconnect");
|
|
3030
|
-
_this.dispatch(setAccountStatus("offline"));
|
|
3031
|
-
_this.dispatch(setConnectionStatus("offline"));
|
|
3032
|
-
},
|
|
3033
|
-
reconnect: function () {
|
|
3034
|
-
log("SERVER: reconnect");
|
|
3035
|
-
_this.dispatch(setAccountStatus("online"));
|
|
3036
|
-
},
|
|
3037
|
-
reconnectError: function () {
|
|
3038
|
-
log("SERVER: reconnect error");
|
|
3039
|
-
_this.dispatch(setAccountStatus("offline"));
|
|
3040
|
-
}
|
|
3041
|
-
};
|
|
3042
2973
|
this.config = config;
|
|
2974
|
+
this.options = options;
|
|
3043
2975
|
this.isNewSession = false;
|
|
3044
2976
|
}
|
|
3045
|
-
StentorDirectChat.prototype.getAvatarPath = function () {
|
|
3046
|
-
return this.avatarPath;
|
|
3047
|
-
};
|
|
3048
2977
|
StentorDirectChat.prototype.init = function (dispatch) {
|
|
3049
2978
|
this.dispatch = dispatch;
|
|
3050
2979
|
// TODO: Authenticate - or at least tell the server who you are
|
|
3051
2980
|
log("got init auth: ".concat(this.config.key));
|
|
3052
2981
|
// We are connected
|
|
3053
|
-
this.
|
|
3054
|
-
this.
|
|
2982
|
+
this.setConnectionStatus("online");
|
|
2983
|
+
this.setAccountStatus("online");
|
|
3055
2984
|
};
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
2985
|
+
StentorDirectChat.prototype.setConnectionStatus = function (status) {
|
|
2986
|
+
log("SERVER: connection_update: ".concat(JSON.stringify(status)));
|
|
2987
|
+
this.dispatch(setConnectionStatus(status));
|
|
2988
|
+
};
|
|
2989
|
+
StentorDirectChat.prototype.setAccountStatus = function (status) {
|
|
2990
|
+
log("SERVER: account_status: ".concat(JSON.stringify(status)));
|
|
2991
|
+
this.dispatch(setAccountStatus(status));
|
|
2992
|
+
};
|
|
2993
|
+
StentorDirectChat.prototype.sendNewMessage = function (data) {
|
|
2994
|
+
log("SERVER: new message: ".concat(JSON.stringify(data)));
|
|
2995
|
+
this.dispatch({
|
|
2996
|
+
type: "chat",
|
|
2997
|
+
detail: {
|
|
2998
|
+
type: "chat.msg",
|
|
2999
|
+
user: __assign(__assign({}, data.user), { nick: "agent:robot" }),
|
|
3000
|
+
msg: data.msg,
|
|
3001
|
+
timestamp: +new Date()
|
|
3002
|
+
}
|
|
3003
|
+
});
|
|
3004
|
+
};
|
|
3005
|
+
StentorDirectChat.prototype.userJoined = function (data) {
|
|
3006
|
+
log("SERVER: user joined: ".concat(JSON.stringify(data)));
|
|
3007
|
+
this.visitorInfo.token = data.token;
|
|
3008
|
+
this.dispatch({
|
|
3009
|
+
type: "chat",
|
|
3010
|
+
detail: {
|
|
3011
|
+
type: "chat.memberjoin",
|
|
3012
|
+
user: __assign(__assign({}, data.user), { nick: "agent:robot" }),
|
|
3013
|
+
timestamp: +new Date(),
|
|
3014
|
+
}
|
|
3015
|
+
});
|
|
3016
|
+
};
|
|
3017
|
+
// private userLeft(data: UserLeaveMessage) {
|
|
3018
|
+
// log(`SERVER: user left: ${JSON.stringify(data)}`);
|
|
3019
|
+
// this.dispatch({
|
|
3020
|
+
// type: "chat",
|
|
3021
|
+
// detail: {
|
|
3022
|
+
// type: "chat.memberleave",
|
|
3023
|
+
// user: {
|
|
3024
|
+
// ...data.user,
|
|
3025
|
+
// nick: "agent:robot",//todo: why change nick?
|
|
3026
|
+
// },
|
|
3027
|
+
// timestamp: +new Date()
|
|
3028
|
+
// }
|
|
3029
|
+
// });
|
|
3030
|
+
// }
|
|
3031
|
+
StentorDirectChat.prototype.typing = function () {
|
|
3032
|
+
this.dispatch({
|
|
3033
|
+
type: "chat",
|
|
3034
|
+
detail: {
|
|
3035
|
+
type: "chat.typing",
|
|
3036
|
+
user: {
|
|
3037
|
+
nick: "agent:robot",
|
|
3038
|
+
},
|
|
3039
|
+
typing: true,
|
|
3040
|
+
timestamp: +new Date()
|
|
3041
|
+
}
|
|
3042
|
+
});
|
|
3043
|
+
};
|
|
3044
|
+
StentorDirectChat.prototype.stopTyping = function () {
|
|
3045
|
+
this.dispatch({
|
|
3046
|
+
type: "chat",
|
|
3047
|
+
detail: {
|
|
3048
|
+
type: "chat.typing",
|
|
3049
|
+
user: {
|
|
3050
|
+
nick: "agent:robot",
|
|
3051
|
+
},
|
|
3052
|
+
typing: false,
|
|
3053
|
+
timestamp: +new Date()
|
|
3054
|
+
}
|
|
3055
|
+
});
|
|
3056
|
+
};
|
|
3057
|
+
// private disconnect() {
|
|
3058
|
+
// log("SERVER: disconnect");
|
|
3059
|
+
// this.dispatch(setAccountStatus("offline"));
|
|
3060
|
+
// this.dispatch(setConnectionStatus("offline"));
|
|
3061
|
+
// }
|
|
3062
|
+
// private reconnect() {
|
|
3063
|
+
// log("SERVER: reconnect");
|
|
3064
|
+
// this.dispatch(setAccountStatus("online"));
|
|
3065
|
+
// }
|
|
3066
|
+
// private reconnectError() {
|
|
3067
|
+
// log("SERVER: reconnect error");
|
|
3068
|
+
// this.dispatch(setAccountStatus("offline"));
|
|
3069
|
+
// }
|
|
3059
3070
|
StentorDirectChat.prototype.sendOfflineMsg = function (_, cb) {
|
|
3060
3071
|
cb();
|
|
3061
3072
|
};
|
|
@@ -3072,6 +3083,17 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3072
3083
|
});
|
|
3073
3084
|
});
|
|
3074
3085
|
};
|
|
3086
|
+
StentorDirectChat.prototype.getBot = function (user) {
|
|
3087
|
+
var _a;
|
|
3088
|
+
var bot = (_a = this.options) === null || _a === void 0 ? void 0 : _a.bot;
|
|
3089
|
+
if (!user) {
|
|
3090
|
+
return bot;
|
|
3091
|
+
}
|
|
3092
|
+
if (user.displayName && user.nick && user.avatarPath) {
|
|
3093
|
+
return user;
|
|
3094
|
+
}
|
|
3095
|
+
return __assign(__assign({}, user), { nick: user.nick || bot.nick || "Bot", displayName: user.displayName || bot.displayName || "Bot", avatarPath: user.avatarPath || bot.avatarPath });
|
|
3096
|
+
};
|
|
3075
3097
|
StentorDirectChat.prototype.sendChatMsgRequest = function (serviceRequest, cb) {
|
|
3076
3098
|
var _a;
|
|
3077
3099
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
@@ -3082,9 +3104,9 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3082
3104
|
case 1:
|
|
3083
3105
|
agentResponse = _b.sent();
|
|
3084
3106
|
if (!((_a = agentResponse.user) === null || _a === void 0 ? void 0 : _a.displayName)) {
|
|
3085
|
-
agentResponse = __assign(__assign({}, agentResponse), { user:
|
|
3107
|
+
agentResponse = __assign(__assign({}, agentResponse), { user: this.getBot(agentResponse.user) });
|
|
3086
3108
|
}
|
|
3087
|
-
this.
|
|
3109
|
+
this.sendNewMessage(agentResponse);
|
|
3088
3110
|
cb();
|
|
3089
3111
|
return [2 /*return*/];
|
|
3090
3112
|
}
|
|
@@ -3096,12 +3118,8 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3096
3118
|
StentorDirectChat.prototype.setVisitorInfo = function (visitorInfo, cb) {
|
|
3097
3119
|
this.visitorInfo = visitorInfo;
|
|
3098
3120
|
this.startSession();
|
|
3099
|
-
this.
|
|
3100
|
-
user:
|
|
3101
|
-
displayName: "Bot",
|
|
3102
|
-
nick: "Bot",
|
|
3103
|
-
avatarPath: this.getAvatarPath()
|
|
3104
|
-
},
|
|
3121
|
+
this.userJoined({
|
|
3122
|
+
user: this.getBot(undefined),
|
|
3105
3123
|
token: ""
|
|
3106
3124
|
});
|
|
3107
3125
|
cb();
|
|
@@ -3210,7 +3228,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3210
3228
|
}
|
|
3211
3229
|
log("Visitor says: ".concat(JSON.stringify(request, undefined, 2)));
|
|
3212
3230
|
// Bot is "typing"
|
|
3213
|
-
this.
|
|
3231
|
+
this.typing();
|
|
3214
3232
|
return [4 /*yield*/, postMessageToStentor(request, this.config.url, this.config.key).catch(function (postError) {
|
|
3215
3233
|
err("POST failed: ".concat(postError.message));
|
|
3216
3234
|
return {
|
|
@@ -3220,7 +3238,7 @@ var StentorDirectChat = /** @class */ (function () {
|
|
|
3220
3238
|
case 1:
|
|
3221
3239
|
botResponse = _e.sent();
|
|
3222
3240
|
// Bot stopped "typing"
|
|
3223
|
-
this.
|
|
3241
|
+
this.stopTyping();
|
|
3224
3242
|
log("Bot says: ".concat(JSON.stringify(botResponse, undefined, 2)));
|
|
3225
3243
|
// Now translate the response to server dialect
|
|
3226
3244
|
// new session no more
|
|
@@ -6618,9 +6636,11 @@ Object.assign(lookup, {
|
|
|
6618
6636
|
});
|
|
6619
6637
|
|
|
6620
6638
|
var StentorServerChat = /** @class */ (function () {
|
|
6621
|
-
|
|
6639
|
+
// private readonly options: ChatServerOptions | undefined;
|
|
6640
|
+
function StentorServerChat(config, options) {
|
|
6622
6641
|
this.config = config;
|
|
6623
|
-
this.
|
|
6642
|
+
// this.options = options;
|
|
6643
|
+
this.token = options.token;
|
|
6624
6644
|
}
|
|
6625
6645
|
StentorServerChat.prototype.init = function (dispatch) {
|
|
6626
6646
|
var _this = this;
|
|
@@ -6780,40 +6800,38 @@ var StentorServerChat = /** @class */ (function () {
|
|
|
6780
6800
|
return StentorServerChat;
|
|
6781
6801
|
}());
|
|
6782
6802
|
|
|
6783
|
-
function createChatServerCore(config,
|
|
6803
|
+
function createChatServerCore(config, options) {
|
|
6784
6804
|
switch (config.type) {
|
|
6785
6805
|
case "direct":
|
|
6786
6806
|
return new StentorDirectChat({
|
|
6787
6807
|
url: config.serverUrl,
|
|
6788
6808
|
key: config.accountKey
|
|
6789
|
-
});
|
|
6809
|
+
}, options);
|
|
6790
6810
|
case "websocket":
|
|
6791
6811
|
return new StentorServerChat({
|
|
6792
|
-
url: config.serverUrl
|
|
6793
|
-
|
|
6794
|
-
});
|
|
6812
|
+
url: config.serverUrl
|
|
6813
|
+
}, options);
|
|
6795
6814
|
case "local":
|
|
6796
6815
|
return new StentorLocalChat();
|
|
6797
6816
|
default:
|
|
6798
6817
|
throw throwBadKind$1(config.type);
|
|
6799
6818
|
}
|
|
6800
6819
|
}
|
|
6801
|
-
function createChatServer(config,
|
|
6802
|
-
return new LogChat(createChatServerCore(config,
|
|
6820
|
+
function createChatServer(config, options) {
|
|
6821
|
+
return new LogChat(createChatServerCore(config, options));
|
|
6803
6822
|
}
|
|
6804
6823
|
var ChatServerContext = React$1.createContext(null);
|
|
6805
|
-
function useChatServer(config) {
|
|
6824
|
+
function useChatServer(config, options) {
|
|
6806
6825
|
var _a = React$1.useState(), server = _a[0], setServer = _a[1];
|
|
6807
|
-
var token = reactRedux.useSelector(function (state) { return state.connection.token; });
|
|
6808
6826
|
var dispatch = useChatDispatch();
|
|
6809
6827
|
React$1.useEffect(function () {
|
|
6810
|
-
var newServer = createChatServer(config,
|
|
6828
|
+
var newServer = createChatServer(config, options);
|
|
6811
6829
|
newServer.init(dispatch);
|
|
6812
6830
|
setServer(newServer);
|
|
6813
6831
|
return function () {
|
|
6814
6832
|
newServer.dispose();
|
|
6815
6833
|
};
|
|
6816
|
-
}, [
|
|
6834
|
+
}, [options, config, dispatch]);
|
|
6817
6835
|
return server;
|
|
6818
6836
|
}
|
|
6819
6837
|
|
|
@@ -7199,7 +7217,7 @@ var MultiSelect = function (props) {
|
|
|
7199
7217
|
var id = ev.target.value;
|
|
7200
7218
|
onChange(__assign(__assign({}, checked), (_a = {}, _a[id] = !checked[id], _a)));
|
|
7201
7219
|
}, [checked, onChange]);
|
|
7202
|
-
return (React__default$1["default"].createElement("ul", { className: "xappw-multiselect" }, items.map(function (item) { return (React__default$1["default"].createElement("li", { key: item.id },
|
|
7220
|
+
return (React__default$1["default"].createElement("ul", { className: "xappw-multiselect" }, items === null || items === void 0 ? void 0 : items.map(function (item) { return (React__default$1["default"].createElement("li", { key: item.id },
|
|
7203
7221
|
React__default$1["default"].createElement("label", null,
|
|
7204
7222
|
React__default$1["default"].createElement("input", { type: "checkbox", checked: checked[item.id] || false, onChange: handleToggle, value: item.id }),
|
|
7205
7223
|
React__default$1["default"].createElement("span", null, item.title)))); })));
|
|
@@ -7705,6 +7723,13 @@ var Suggestions = function (props) {
|
|
|
7705
7723
|
var currentIndex = len > 0 ? props.index : NaN;
|
|
7706
7724
|
var _a = React$1.useState(), activeItem = _a[0], setActiveItem = _a[1];
|
|
7707
7725
|
var item = React$1.useMemo(function () { return findItemByIndex_1(data, currentIndex); }, [data, currentIndex]);
|
|
7726
|
+
var handleSpanClick = React$1.useCallback(function (target, span) {
|
|
7727
|
+
if (span.type === "inputText") {
|
|
7728
|
+
onItemUse(target);
|
|
7729
|
+
return false;
|
|
7730
|
+
}
|
|
7731
|
+
return undefined;
|
|
7732
|
+
}, [onItemUse]);
|
|
7708
7733
|
React$1.useEffect(function () {
|
|
7709
7734
|
setActiveItem(item);
|
|
7710
7735
|
}, [item]);
|
|
@@ -7712,7 +7737,7 @@ var Suggestions = function (props) {
|
|
|
7712
7737
|
return (React__default$1["default"].createElement("div", { className: "xappw-suggestions ".concat(props.className || "") },
|
|
7713
7738
|
(activeItem === null || activeItem === void 0 ? void 0 : activeItem.content) && React__default$1["default"].createElement("div", { className: "xappw-suggestions__answer" }, activeItem.content),
|
|
7714
7739
|
!!data.length &&
|
|
7715
|
-
React__default$1["default"].createElement(SuggestionsList_1, { suggestions: data, index: currentIndex, className: "xappw-suggestions__groups", itemActions: actions, onItemClick: props.onItemClick, onItemHover: setActiveItem })));
|
|
7740
|
+
React__default$1["default"].createElement(SuggestionsList_1, { suggestions: data, index: currentIndex, className: "xappw-suggestions__groups", itemActions: actions, onItemClick: props.onItemClick, onItemHover: setActiveItem, onSpanClick: handleSpanClick })));
|
|
7716
7741
|
};
|
|
7717
7742
|
|
|
7718
7743
|
var ChatFooter = function (props) {
|
|
@@ -7970,9 +7995,9 @@ var QueuePosition = function (props) {
|
|
|
7970
7995
|
function getMessageByType(msg) {
|
|
7971
7996
|
switch (msg.type) {
|
|
7972
7997
|
case "chat.memberjoin":
|
|
7973
|
-
return "".concat(msg.user.displayName, " has joined the chat");
|
|
7998
|
+
return "".concat(msg.user.displayName || "Bot", " has joined the chat");
|
|
7974
7999
|
case "chat.memberleave":
|
|
7975
|
-
return "".concat(msg.user.displayName, " has left the chat");
|
|
8000
|
+
return "".concat(msg.user.displayName || "Bot", " has left the chat");
|
|
7976
8001
|
case "chat.rating":
|
|
7977
8002
|
if (!msg.newRating) {
|
|
7978
8003
|
return "You have removed the chat rating";
|
|
@@ -8036,7 +8061,7 @@ var MessageList = function (props) {
|
|
|
8036
8061
|
var messagesEndRef = React$1.useRef(null);
|
|
8037
8062
|
React$1.useEffect(function () {
|
|
8038
8063
|
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
8039
|
-
}, [props.messages]);
|
|
8064
|
+
}, [props.messages, props.agents]);
|
|
8040
8065
|
var handleSend = React$1.useCallback(function (msg) {
|
|
8041
8066
|
onSend(msg);
|
|
8042
8067
|
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
@@ -8401,7 +8426,18 @@ var ChatWidgetWrapper = function (props) {
|
|
|
8401
8426
|
var _a;
|
|
8402
8427
|
return (__assign(__assign({}, rawConfig), { connection: connection, assetUrl: (_a = connection === null || connection === void 0 ? void 0 : connection.serverUrl) !== null && _a !== void 0 ? _a : defaultServerUrl, env: rawConfig }));
|
|
8403
8428
|
}, [connection, rawConfig]);
|
|
8404
|
-
var
|
|
8429
|
+
var token = reactRedux.useSelector(function (state) { return state.connection.token; });
|
|
8430
|
+
var options = React$1.useMemo(function () {
|
|
8431
|
+
return {
|
|
8432
|
+
token: token,
|
|
8433
|
+
bot: {
|
|
8434
|
+
nick: "Bot",
|
|
8435
|
+
displayName: rawConfig.botName,
|
|
8436
|
+
avatarPath: rawConfig.avatarUrl
|
|
8437
|
+
}
|
|
8438
|
+
};
|
|
8439
|
+
}, [token, rawConfig]);
|
|
8440
|
+
var chatServer = useChatServer(connection, options);
|
|
8405
8441
|
return (React__default$1["default"].createElement(ChatConfigContext.Provider, { value: config },
|
|
8406
8442
|
React__default$1["default"].createElement(ChatServerContext.Provider, { value: chatServer },
|
|
8407
8443
|
React__default$1["default"].createElement(ChatWidget, __assign({}, props)))));
|
|
@@ -8631,7 +8667,7 @@ function memberJoin(state, detail) {
|
|
|
8631
8667
|
var _a;
|
|
8632
8668
|
if (isAgent(detail.user.nick)) {
|
|
8633
8669
|
var prevAgentInfo = state.agents[detail.user.nick];
|
|
8634
|
-
return __assign(__assign({}, state), { isChatting: true, chats: (prevAgentInfo === null || prevAgentInfo === void 0 ? void 0 : prevAgentInfo.joined) ?
|
|
8670
|
+
return __assign(__assign({}, state), { isChatting: true, chats: (prevAgentInfo === null || prevAgentInfo === void 0 ? void 0 : prevAgentInfo.joined) ? joinMessages([], detail) : joinMessages(state.chats, detail), agents: (_a = {},
|
|
8635
8671
|
_a[detail.user.nick] = __assign(__assign({}, prevAgentInfo), { user: __assign(__assign({}, detail.user), { displayName: detail.user.displayName || "Agent" }), joined: true, typing: false }),
|
|
8636
8672
|
_a) });
|
|
8637
8673
|
}
|