, "user");
+ fileUrl={fileDetails.fileUrl}/>, "USER");
}
/**
diff --git a/src/components/ChatBotBody/ChatBotBody.tsx b/src/components/ChatBotBody/ChatBotBody.tsx
index bc9cbf83..8681de21 100644
--- a/src/components/ChatBotBody/ChatBotBody.tsx
+++ b/src/components/ChatBotBody/ChatBotBody.tsx
@@ -212,13 +212,13 @@ const ChatBotBody = ({
onScroll={updateIsScrolling}
>
{messages.map((message, index) => {
- if (message.sender === "system") {
+ if (message.sender.toUpperCase() === "SYSTEM") {
return {message.content}
}
return (
- {message.sender === "user"
+ {message.sender.toUpperCase() === "USER"
? renderUserMessage(message, index)
: renderBotMessage(message, index)}
diff --git a/src/hooks/internal/useMessagesInternal.ts b/src/hooks/internal/useMessagesInternal.ts
index a8245fb8..3b7fce10 100644
--- a/src/hooks/internal/useMessagesInternal.ts
+++ b/src/hooks/internal/useMessagesInternal.ts
@@ -50,6 +50,9 @@ export const useMessagesInternal = () => {
* @param useMarkup boolean indicating whether markup is used
*/
const simulateStream = useCallback(async (message: Message, streamSpeed: number, useMarkup: boolean) => {
+ // always convert to uppercase for checks
+ message.sender = message.sender.toUpperCase();
+
// stop bot typing when simulating stream
setIsBotTyping(false);
@@ -113,7 +116,10 @@ export const useMessagesInternal = () => {
* @param sender sender of the message, defaults to bot
*/
const injectMessage = useCallback(async (content: string | JSX.Element,
- sender = "bot"): Promise => {
+ sender = "BOT"): Promise => {
+
+ // always convert to uppercase for checks
+ sender = sender.toUpperCase();
let message = createMessage(content, sender);
@@ -127,17 +133,17 @@ export const useMessagesInternal = () => {
}
let useMarkup = false;
- if (sender === "bot") {
+ if (sender === "BOT") {
useMarkup = settings.botBubble?.dangerouslySetInnerHtml as boolean;
- } else if (sender === "user") {
+ } else if (sender === "USER") {
useMarkup = settings.userBubble?.dangerouslySetInnerHtml as boolean;
}
processAudio(settings, audioToggledOn, isChatWindowOpen, message, useMarkup);
const isBotStream = typeof message.content === "string"
- && message.sender === "bot" && settings?.botBubble?.simStream;
+ && message.sender === "BOT" && settings?.botBubble?.simStream;
const isUserStream = typeof message.content === "string"
- && message.sender === "user" && settings?.userBubble?.simStream;
+ && message.sender === "USER" && settings?.userBubble?.simStream;
// handles post-message inject event
setUnreadCount(prev => prev + 1);
@@ -197,7 +203,10 @@ export const useMessagesInternal = () => {
* @param sender sender of the message, defaults to bot
*/
const streamMessage = useCallback(async (content: string | JSX.Element,
- sender = "bot"): Promise => {
+ sender = "BOT"): Promise => {
+
+ // always convert to uppercase for checks
+ sender = sender.toUpperCase();
if (!streamMessageMap.current.has(sender)) {
const message = createMessage(content, sender);
@@ -261,7 +270,10 @@ export const useMessagesInternal = () => {
* be made mandatory. Another key implication of not using `endStreamMessage` in v2 is that the stop stream
* message event will not be emitted, which may be problematic for logic (or plugins) that rely on this event.
*/
- const endStreamMessage = useCallback(async (sender = "bot"): Promise => {
+ const endStreamMessage = useCallback(async (sender = "BOT"): Promise => {
+ // always convert to uppercase for checks
+ sender = sender.toUpperCase();
+
// nothing to end if not streaming
if (!streamMessageMap.current.has(sender)) {
return true;
@@ -306,7 +318,7 @@ export const useMessagesInternal = () => {
const lastMessage = updatedMessages[updatedMessages.length - 1];
// if message is sent by user or is bot typing or bot is embedded, return
- if (!lastMessage || lastMessage.sender === "user") {
+ if (!lastMessage || lastMessage.sender === "USER") {
shouldNotify = false;
}
diff --git a/src/hooks/internal/useSubmitInputInternal.ts b/src/hooks/internal/useSubmitInputInternal.ts
index 411746df..f0a14f8f 100644
--- a/src/hooks/internal/useSubmitInputInternal.ts
+++ b/src/hooks/internal/useSubmitInputInternal.ts
@@ -78,12 +78,12 @@ export const useSubmitInputInternal = () => {
if (settings?.sensitiveInput?.hideInUserBubble) {
return;
} else if (settings?.sensitiveInput?.maskInUserBubble) {
- await injectMessage("*".repeat(settings.sensitiveInput?.asterisksCount as number ?? 10), "user");
+ await injectMessage("*".repeat(settings.sensitiveInput?.asterisksCount as number ?? 10), "USER");
return;
}
}
- await injectMessage(userInput, "user");
+ await injectMessage(userInput, "USER");
}, [flowRef, getCurrPath, settings, injectMessage, textAreaSensitiveMode]);
/**
diff --git a/src/services/AudioService.ts b/src/services/AudioService.ts
index 9ddda0fa..7d517553 100644
--- a/src/services/AudioService.ts
+++ b/src/services/AudioService.ts
@@ -57,7 +57,7 @@ export const processAudio = (settings: Settings, voiceToggledOn: boolean,
isChatWindowOpen: boolean, message: Message, useMarkup: boolean) => {
// Add check for empty message content
- if (settings.audio?.disabled || message.sender === "user" || typeof message.content !== "string"
+ if (settings.audio?.disabled || message.sender.toUpperCase() === "USER" || typeof message.content !== "string"
|| (!isChatWindowOpen && !settings.general?.embedded) || !voiceToggledOn
|| message.content.trim() === "") { // Check for empty message content
return;
diff --git a/src/services/ChatHistoryService.tsx b/src/services/ChatHistoryService.tsx
index fe64acd2..e78d7412 100644
--- a/src/services/ChatHistoryService.tsx
+++ b/src/services/ChatHistoryService.tsx
@@ -32,7 +32,7 @@ const saveChatHistory = async (messages: Message[]) => {
for (let i = messages.length - 1; i >= offset; i--) {
const message = messages[i];
- if (message.sender === "system") {
+ if (message.sender.toUpperCase() === "SYSTEM") {
break;
}
@@ -127,7 +127,7 @@ const parseMessageToString = (message: Message) => {
id: message.id,
content: ReactDOMServer.renderToString(message.content),
type: message.type,
- sender: message.sender,
+ sender: message.sender.toUpperCase(),
timestamp: message.timestamp
});
return clonedMessage;