@aslaluroba/help-center-react 3.0.3 → 3.0.4
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.esm.js +30 -58
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -58
- package/dist/index.js.map +1 -1
- package/dist/ui/chatbot-popup/chat-window-screen/footer.d.ts +0 -1
- package/dist/ui/chatbot-popup/chat-window-screen/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/ui/chatbot-popup/chat-window-screen/footer.tsx +1 -2
- package/src/ui/chatbot-popup/chat-window-screen/index.tsx +96 -99
- package/src/ui/help-center.tsx +28 -66
- package/src/ui/help-popup.tsx +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -10802,7 +10802,7 @@ const ChatWindowFooter = (props) => {
|
|
|
10802
10802
|
const { t, dir } = useLocalTranslation();
|
|
10803
10803
|
return (React__default.createElement("footer", { className: 'babylai-flex babylai-items-center babylai-gap-2 babylai-relative babylai-rounded-full babylai-bg-white dark:!babylai-bg-storm-dust-900 babylai-m-4 md:babylai-m-6 md:babylai-py-3 md:babylai-px-4' },
|
|
10804
10804
|
React__default.createElement("input", { type: 'text', value: props.inputMessage, onChange: (e) => props.setInputMessage(e.target.value), onKeyDown: props.handleKeyDown, placeholder: t('homeSdk.placeholder'), className: 'babylai-flex-1 babylai-py-2 babylai-px-4 babylai-bg-transparent babylai-outline-none babylai-text-sm dark:babylai-text-white' }),
|
|
10805
|
-
React__default.createElement(Button, { variant: 'default', size: 'icon', onClick: props.handleSendMessage, disabled:
|
|
10805
|
+
React__default.createElement(Button, { variant: 'default', size: 'icon', onClick: props.handleSendMessage, disabled: props === null || props === void 0 ? void 0 : props.isLoading, className: 'babylai-rounded-full babylai-bg-purple-500 babylai-hover:babylai-bg-purple-600 babylai-w-8 babylai-h-8 babylai-disabled:babylai-opacity-50' },
|
|
10806
10806
|
React__default.createElement(SvgEnvelope, { className: `babylai-w-4 babylai-h-4 ${dir === 'rtl' ? 'babylai-rotate-270' : ''}` }))));
|
|
10807
10807
|
};
|
|
10808
10808
|
|
|
@@ -10866,7 +10866,7 @@ const TypingIndicator = React__default.memo(({ firstHumanAgentIndex }) => {
|
|
|
10866
10866
|
React__default.createElement("p", { className: 'babylai-text-sm babylai-opacity-70 dark:babylai-text-white' }, "..."))));
|
|
10867
10867
|
});
|
|
10868
10868
|
TypingIndicator.displayName = 'TypingIndicator';
|
|
10869
|
-
const ChatWindow = React__default.memo(({ onSendMessage, messages, assistantStatus = 'loading'
|
|
10869
|
+
const ChatWindow = React__default.memo(({ onSendMessage, messages, assistantStatus = 'loading' }) => {
|
|
10870
10870
|
const [inputMessage, setInputMessage] = useState('');
|
|
10871
10871
|
const messagesEndRef = useRef(null);
|
|
10872
10872
|
const scrollTimeoutRef = useRef(null);
|
|
@@ -10906,14 +10906,14 @@ const ChatWindow = React__default.memo(({ onSendMessage, messages, assistantStat
|
|
|
10906
10906
|
}
|
|
10907
10907
|
}, [inputMessage, onSendMessage]);
|
|
10908
10908
|
const handleKeyDown = useCallback((e) => {
|
|
10909
|
-
if (e.key === 'Enter' && !e.shiftKey
|
|
10909
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
10910
10910
|
e.preventDefault();
|
|
10911
10911
|
if (inputMessage.trim() && assistantStatus !== 'typing') {
|
|
10912
10912
|
onSendMessage(inputMessage);
|
|
10913
10913
|
setInputMessage('');
|
|
10914
10914
|
}
|
|
10915
10915
|
}
|
|
10916
|
-
}, [inputMessage, onSendMessage, assistantStatus
|
|
10916
|
+
}, [inputMessage, onSendMessage, assistantStatus]);
|
|
10917
10917
|
// Memoize the first human agent index calculation
|
|
10918
10918
|
const firstHumanAgentIndex = useMemo(() => {
|
|
10919
10919
|
return messages.findIndex((message) => message.senderType === 2);
|
|
@@ -10934,7 +10934,7 @@ const ChatWindow = React__default.memo(({ onSendMessage, messages, assistantStat
|
|
|
10934
10934
|
messagesList,
|
|
10935
10935
|
assistantStatus === 'typing' && React__default.createElement(TypingIndicator, { firstHumanAgentIndex: firstHumanAgentIndex }),
|
|
10936
10936
|
React__default.createElement("div", { ref: messagesEndRef })),
|
|
10937
|
-
React__default.createElement(ChatWindowFooter, { inputMessage: inputMessage, handleKeyDown: handleKeyDown, handleSendMessage: handleSendMessage, setInputMessage: setInputMessage, isLoading: isLoading
|
|
10937
|
+
React__default.createElement(ChatWindowFooter, { inputMessage: inputMessage, handleKeyDown: handleKeyDown, handleSendMessage: handleSendMessage, setInputMessage: setInputMessage, isLoading: isLoading })));
|
|
10938
10938
|
});
|
|
10939
10939
|
ChatWindow.displayName = 'ChatWindow';
|
|
10940
10940
|
|
|
@@ -11250,10 +11250,10 @@ function HelpPopup({ onClose, helpScreen, status, error, onStartChat, onSendMess
|
|
|
11250
11250
|
}
|
|
11251
11251
|
}, [onStartChat, setSelectedOption, sessionId, setStartNewChatConfirmation, setTempSelectedOption]);
|
|
11252
11252
|
const handleSendMessage = useCallback((message) => {
|
|
11253
|
-
if (message.trim()
|
|
11253
|
+
if (message.trim()) {
|
|
11254
11254
|
onSendMessage(message.trim());
|
|
11255
11255
|
}
|
|
11256
|
-
}, [onSendMessage
|
|
11256
|
+
}, [onSendMessage]);
|
|
11257
11257
|
const hideEndChatConfirmation = useCallback(() => {
|
|
11258
11258
|
setEndChatConfirmation(false);
|
|
11259
11259
|
}, []);
|
|
@@ -11437,14 +11437,23 @@ function HelpCenter({ helpScreenId, user, showArrow = true, language = 'en', mes
|
|
|
11437
11437
|
setReviewSessionId(null);
|
|
11438
11438
|
};
|
|
11439
11439
|
const handleStartChat = async (option) => {
|
|
11440
|
-
|
|
11440
|
+
var _a;
|
|
11441
|
+
setMessages([
|
|
11442
|
+
{
|
|
11443
|
+
id: Date.now(),
|
|
11444
|
+
senderType: 3,
|
|
11445
|
+
messageContent: ((_a = option === null || option === void 0 ? void 0 : option.assistant) === null || _a === void 0 ? void 0 : _a.greeting) || 'مرحباً! كيف يمكنني مساعدتك اليوم؟',
|
|
11446
|
+
sentAt: new Date(),
|
|
11447
|
+
isSeen: true,
|
|
11448
|
+
},
|
|
11449
|
+
]);
|
|
11450
|
+
setIsChatClosed(false);
|
|
11451
|
+
setStatus('succeeded');
|
|
11441
11452
|
};
|
|
11442
11453
|
const startNewChatSession = async (option) => {
|
|
11443
|
-
var _a;
|
|
11444
11454
|
try {
|
|
11445
11455
|
setStatus('loading');
|
|
11446
11456
|
setError('');
|
|
11447
|
-
setMessages([]);
|
|
11448
11457
|
const chatSessionCreateDto = {
|
|
11449
11458
|
helpScreenId: helpScreenId,
|
|
11450
11459
|
optionId: option.id,
|
|
@@ -11461,30 +11470,9 @@ function HelpCenter({ helpScreenId, user, showArrow = true, language = 'en', mes
|
|
|
11461
11470
|
throw new Error('Failed to create chat session');
|
|
11462
11471
|
}
|
|
11463
11472
|
const responseData = await response.json();
|
|
11464
|
-
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
{
|
|
11468
|
-
id: Date.now(),
|
|
11469
|
-
senderType: 3,
|
|
11470
|
-
messageContent: responseData.chatSession.assistant.greeting,
|
|
11471
|
-
sentAt: new Date(),
|
|
11472
|
-
isSeen: true,
|
|
11473
|
-
},
|
|
11474
|
-
]);
|
|
11475
|
-
}
|
|
11476
|
-
else {
|
|
11477
|
-
setMessages([
|
|
11478
|
-
{
|
|
11479
|
-
id: Date.now(),
|
|
11480
|
-
senderType: 3,
|
|
11481
|
-
messageContent: 'Hello! How can I assist you today?\nمرحباً! كيف يمكنني مساعدتك اليوم؟',
|
|
11482
|
-
sentAt: new Date(),
|
|
11483
|
-
isSeen: true,
|
|
11484
|
-
},
|
|
11485
|
-
]);
|
|
11486
|
-
}
|
|
11487
|
-
await ClientAblyService.startConnection(responseData.chatSession.id, responseData.ablyToken, handleReceiveMessage, responseData.chatSession.tenantId);
|
|
11473
|
+
const newSessionId = responseData.chatSession.id;
|
|
11474
|
+
setSessionId(newSessionId);
|
|
11475
|
+
await ClientAblyService.startConnection(newSessionId, responseData.ablyToken, handleReceiveMessage, responseData.chatSession.tenantId);
|
|
11488
11476
|
// Verify the connection is actually active
|
|
11489
11477
|
if (!ClientAblyService.isConnectionActive()) {
|
|
11490
11478
|
throw new Error('Ably connection failed to establish properly');
|
|
@@ -11492,19 +11480,15 @@ function HelpCenter({ helpScreenId, user, showArrow = true, language = 'en', mes
|
|
|
11492
11480
|
setIsAblyConnected(true);
|
|
11493
11481
|
setIsChatClosed(false);
|
|
11494
11482
|
setStatus('succeeded');
|
|
11483
|
+
return newSessionId; // Return the session ID
|
|
11495
11484
|
}
|
|
11496
11485
|
catch (error) {
|
|
11497
11486
|
setError(error instanceof Error ? error.message : 'Failed to start chat session');
|
|
11498
11487
|
setStatus('failed');
|
|
11488
|
+
throw error; // Re-throw to handle in calling function
|
|
11499
11489
|
}
|
|
11500
11490
|
};
|
|
11501
11491
|
const handleSendMessage = async (message) => {
|
|
11502
|
-
// Only send message if Ably is connected
|
|
11503
|
-
if (!isAblyConnected) {
|
|
11504
|
-
setError('Connection lost. Please try again.');
|
|
11505
|
-
return;
|
|
11506
|
-
}
|
|
11507
|
-
let currentSessionId = sessionId;
|
|
11508
11492
|
if (message.trim() !== '') {
|
|
11509
11493
|
try {
|
|
11510
11494
|
setAssistantStatus('typing');
|
|
@@ -11516,25 +11500,13 @@ function HelpCenter({ helpScreenId, user, showArrow = true, language = 'en', mes
|
|
|
11516
11500
|
isSeen: false,
|
|
11517
11501
|
};
|
|
11518
11502
|
setMessages((prevMessages) => [...prevMessages, userMessage]);
|
|
11503
|
+
// Handle session creation if needed
|
|
11504
|
+
let currentSessionId = sessionId;
|
|
11505
|
+
if (!isAblyConnected && selectedOption) {
|
|
11506
|
+
currentSessionId = await startNewChatSession(selectedOption);
|
|
11507
|
+
}
|
|
11519
11508
|
if (!currentSessionId) {
|
|
11520
|
-
|
|
11521
|
-
helpScreenId: helpScreenId,
|
|
11522
|
-
optionId: selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.id,
|
|
11523
|
-
user: {
|
|
11524
|
-
id: user === null || user === void 0 ? void 0 : user.id,
|
|
11525
|
-
name: user === null || user === void 0 ? void 0 : user.name,
|
|
11526
|
-
email: user === null || user === void 0 ? void 0 : user.email,
|
|
11527
|
-
},
|
|
11528
|
-
};
|
|
11529
|
-
const response = await apiRequest('Client/ClientChatSession/create-session', 'POST', chatSessionCreateDto);
|
|
11530
|
-
if (!response.ok) {
|
|
11531
|
-
throw new Error('Failed to create chat session');
|
|
11532
|
-
}
|
|
11533
|
-
const responseData = await response.json();
|
|
11534
|
-
setSessionId(responseData.chatSession.id);
|
|
11535
|
-
currentSessionId = responseData.chatSession.id;
|
|
11536
|
-
await ClientAblyService.startConnection(responseData.chatSession.id, responseData.ablyToken, handleReceiveMessage, responseData.chatSession.tenantId);
|
|
11537
|
-
setIsAblyConnected(true);
|
|
11509
|
+
throw new Error('No active session available');
|
|
11538
11510
|
}
|
|
11539
11511
|
const messageDto = { messageContent: message };
|
|
11540
11512
|
const response = await apiRequest(`Client/ClientChatSession/${currentSessionId}/send-message`, 'POST', messageDto);
|