Enhanced Chat Embed Configuration View (#3559)

* Changes Made to Embed Chat Configuration
1. Consolidated multiple configuration functions into a single `defaultThemeConfig` object
2. Added full theme configuration support for both popup and fullpage modes
3. Fixed fullpage chat window sizing to use 100% height and width
4. Improved code formatting and readability

* fix: replace empty customCSS quotes with backticks in theme configuration output

* refactor: improve script output formatting for embed chat code

* Fixed incorrect spacing in React component theme prop string templates.
This commit is contained in:
toi500
2024-11-26 00:08:59 +01:00
committed by GitHub
parent 7d9e1514b1
commit af5e6b0968
+115 -132
View File
@@ -53,7 +53,10 @@ const embedPopupReactCode = (chatflowid) => {
const App = () => { const App = () => {
return ( return (
<BubbleChat chatflowid="${chatflowid}" apiHost="${baseURL}" /> <BubbleChat
chatflowid="${chatflowid}"
apiHost="${baseURL}"
/>
); );
};` };`
} }
@@ -82,84 +85,67 @@ const App = () => {
};` };`
} }
const buttonConfig = (isReact = false) => { export const defaultThemeConfig = {
return isReact button: {
? `button: { backgroundColor: '#3B81F6',
backgroundColor: "#3B81F6",
right: 20, right: 20,
bottom: 20, bottom: 20,
size: 48, // small | medium | large | number size: 48,
dragAndDrop: true, dragAndDrop: true,
iconColor: "white", iconColor: 'white',
customIconSrc: "https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg", customIconSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
autoWindowOpen: { autoWindowOpen: {
autoOpen: true, //parameter to control automatic window opening autoOpen: true,
openDelay: 2, // Optional parameter for delay time in seconds openDelay: 2,
autoOpenOnMobile: false, //parameter to control automatic window opening in mobile autoOpenOnMobile: false
}
}, },
}` tooltip: {
: `button: {
backgroundColor: "#3B81F6",
right: 20,
bottom: 20,
size: 48, // small | medium | large | number
dragAndDrop: true,
iconColor: "white",
customIconSrc: "https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg",
autoWindowOpen: {
autoOpen: true, //parameter to control automatic window opening
openDelay: 2, // Optional parameter for delay time in seconds
autoOpenOnMobile: false, //parameter to control automatic window opening in mobile
},
}`
}
const tooltipConfig = (isReact = false) => {
return isReact
? `tooltip: {
showTooltip: true, showTooltip: true,
tooltipMessage: 'Hi There 👋!', tooltipMessage: 'Hi There 👋!',
tooltipBackgroundColor: 'black', tooltipBackgroundColor: 'black',
tooltipTextColor: 'white', tooltipTextColor: 'white',
tooltipFontSize: 16, tooltipFontSize: 16
}` },
: `tooltip: { disclaimer: {
showTooltip: true, title: 'Disclaimer',
tooltipMessage: 'Hi There 👋!', message: 'By using this chatbot, you agree to the <a target="_blank" href="https://flowiseai.com/terms">Terms & Condition</a>',
tooltipBackgroundColor: 'black', textColor: 'black',
tooltipTextColor: 'white', buttonColor: '#3b82f6',
tooltipFontSize: 16, buttonText: 'Start Chatting',
}` buttonTextColor: 'white',
} blurredBackgroundColor: 'rgba(0, 0, 0, 0.4)',
backgroundColor: 'white'
const chatwindowConfig = (isReact = false) => { },
return isReact customCSS: ``,
? `chatWindow: { chatWindow: {
showTitle: true, showTitle: true,
showAgentMessages: true,
title: 'Flowise Bot', title: 'Flowise Bot',
titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg', titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
showAgentMessages: true,
welcomeMessage: 'Hello! This is custom welcome message', welcomeMessage: 'Hello! This is custom welcome message',
errorMessage: 'This is a custom error message', errorMessage: 'This is a custom error message',
backgroundColor: "#ffffff", backgroundColor: '#ffffff',
backgroundImage: 'enter image path or link', // If set, this will overlap the background color of the chat window. backgroundImage: 'enter image path or link',
height: 700, height: 700,
width: 400, width: 400,
fontSize: 16, fontSize: 16,
//starterPrompts: ['What is a bot?', 'Who are you?'], // It overrides the starter prompts set by the chat flow passed starterPrompts: ['What is a bot?', 'Who are you?'],
starterPromptFontSize: 15, starterPromptFontSize: 15,
clearChatOnReload: false, // If set to true, the chat will be cleared when the page reloads. clearChatOnReload: false,
sourceDocsTitle: 'Sources:',
renderHTML: true,
botMessage: { botMessage: {
backgroundColor: "#f7f8ff", backgroundColor: '#f7f8ff',
textColor: "#303235", textColor: '#303235',
showAvatar: true, showAvatar: true,
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png", avatarSrc: 'https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png'
}, },
userMessage: { userMessage: {
backgroundColor: "#3B81F6", backgroundColor: '#3B81F6',
textColor: "#ffffff", textColor: '#ffffff',
showAvatar: true, showAvatar: true,
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png", avatarSrc: 'https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png'
}, },
textInput: { textInput: {
placeholder: 'Type your question', placeholder: 'Type your question',
@@ -168,72 +154,41 @@ const chatwindowConfig = (isReact = false) => {
sendButtonColor: '#3B81F6', sendButtonColor: '#3B81F6',
maxChars: 50, maxChars: 50,
maxCharsWarningMessage: 'You exceeded the characters limit. Please input less than 50 characters.', maxCharsWarningMessage: 'You exceeded the characters limit. Please input less than 50 characters.',
autoFocus: true, // If not used, autofocus is disabled on mobile and enabled on desktop. true enables it on both, false disables it on both. autoFocus: true,
sendMessageSound: true, sendMessageSound: true,
// sendSoundLocation: "send_message.mp3", // If this is not used, the default sound effect will be played if sendSoundMessage is true. sendSoundLocation: 'send_message.mp3',
receiveMessageSound: true, receiveMessageSound: true,
// receiveSoundLocation: "receive_message.mp3", // If this is not used, the default sound effect will be played if receiveSoundMessage is true. receiveSoundLocation: 'receive_message.mp3'
}, },
feedback: { feedback: {
color: '#303235', color: '#303235'
},
dateTimeToggle: {
date: true,
time: true
}, },
footer: { footer: {
textColor: '#303235', textColor: '#303235',
text: 'Powered by', text: 'Powered by',
company: 'Flowise', company: 'Flowise',
companyLink: 'https://flowiseai.com', companyLink: 'https://flowiseai.com'
} }
}`
: `chatWindow: {
showTitle: true,
title: 'Flowise Bot',
titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
showAgentMessages: true,
welcomeMessage: 'Hello! This is custom welcome message',
errorMessage: 'This is a custom error message',
backgroundColor: "#ffffff",
backgroundImage: 'enter image path or link', // If set, this will overlap the background color of the chat window.
height: 700,
width: 400,
fontSize: 16,
//starterPrompts: ['What is a bot?', 'Who are you?'], // It overrides the starter prompts set by the chat flow passed
starterPromptFontSize: 15,
clearChatOnReload: false, // If set to true, the chat will be cleared when the page reloads.
botMessage: {
backgroundColor: "#f7f8ff",
textColor: "#303235",
showAvatar: true,
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png",
},
userMessage: {
backgroundColor: "#3B81F6",
textColor: "#ffffff",
showAvatar: true,
avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png",
},
textInput: {
placeholder: 'Type your question',
backgroundColor: '#ffffff',
textColor: '#303235',
sendButtonColor: '#3B81F6',
maxChars: 50,
maxCharsWarningMessage: 'You exceeded the characters limit. Please input less than 50 characters.',
autoFocus: true, // If not used, autofocus is disabled on mobile and enabled on desktop. true enables it on both, false disables it on both.
sendMessageSound: true,
// sendSoundLocation: "send_message.mp3", // If this is not used, the default sound effect will be played if sendSoundMessage is true.
receiveMessageSound: true,
// receiveSoundLocation: "receive_message.mp3", // If this is not used, the default sound effect will be played if receiveSoundMessage is true.
},
feedback: {
color: '#303235',
},
footer: {
textColor: '#303235',
text: 'Powered by',
company: 'Flowise',
companyLink: 'https://flowiseai.com',
} }
}` }
const customStringify = (obj) => {
let stringified = JSON.stringify(obj, null, 4)
.replace(/"([^"]+)":/g, '$1:')
.replace(/: "([^"]+)"/g, (match, value) => (value.includes('<') ? `: "${value}"` : `: '${value}'`))
.replace(/: "(true|false|\d+)"/g, ': $1')
.replace(/customCSS: ""/g, 'customCSS: ``')
return stringified
.split('\n')
.map((line, index) => {
if (index === 0) return line
return ' '.repeat(8) + line
})
.join('\n')
} }
const embedPopupHtmlCodeCustomization = (chatflowid) => { const embedPopupHtmlCodeCustomization = (chatflowid) => {
@@ -243,13 +198,12 @@ const embedPopupHtmlCodeCustomization = (chatflowid) => {
chatflowid: "${chatflowid}", chatflowid: "${chatflowid}",
apiHost: "${baseURL}", apiHost: "${baseURL}",
chatflowConfig: { chatflowConfig: {
// topK: 2 /* Chatflow Config */
}, },
theme: { observersConfig: {
${buttonConfig()}, /* Observers Config */
${tooltipConfig()}, },
${chatwindowConfig()} theme: ${customStringify(defaultThemeConfig)}
}
}) })
</script>` </script>`
} }
@@ -262,14 +216,31 @@ const App = () => {
<BubbleChat <BubbleChat
chatflowid="${chatflowid}" chatflowid="${chatflowid}"
apiHost="${baseURL}" apiHost="${baseURL}"
theme={{ chatflowConfig={{
${buttonConfig(true)}, /* Chatflow Config */
${tooltipConfig(true)},
${chatwindowConfig(true)}
}} }}
observersConfig={{
/* Observers Config */
}}
theme={{${customStringify(defaultThemeConfig)
.substring(1)
.split('\n')
.map((line) => ' '.repeat(4) + line)
.join('\n')}
/> />
); )
};` }`
}
const getFullPageThemeConfig = () => {
return {
...defaultThemeConfig,
chatWindow: {
...defaultThemeConfig.chatWindow,
height: '100%',
width: '100%'
}
}
} }
const embedFullpageHtmlCodeCustomization = (chatflowid) => { const embedFullpageHtmlCodeCustomization = (chatflowid) => {
@@ -279,27 +250,39 @@ const embedFullpageHtmlCodeCustomization = (chatflowid) => {
Chatbot.initFull({ Chatbot.initFull({
chatflowid: "${chatflowid}", chatflowid: "${chatflowid}",
apiHost: "${baseURL}", apiHost: "${baseURL}",
theme: { chatflowConfig: {
${chatwindowConfig()} /* Chatflow Config */
} },
observersConfig: {
/* Observers Config */
},
theme: ${customStringify(getFullPageThemeConfig())}
}) })
</script>` </script>`
} }
const embedFullpageReactCodeCustomization = (chatflowid) => { const embedFullpageReactCodeCustomization = (chatflowid) => {
return `import { FullPageChat } from "flowise-embed-react" return `import { FullPageChat } from 'flowise-embed-react'
const App = () => { const App = () => {
return ( return (
<FullPageChat <FullPageChat
chatflowid="${chatflowid}" chatflowid="${chatflowid}"
apiHost="${baseURL}" apiHost="${baseURL}"
theme={{ chatflowConfig={{
${chatwindowConfig(true)} /* Chatflow Config */
}} }}
observersConfig={{
/* Observers Config */
}}
theme={{${customStringify(getFullPageThemeConfig())
.substring(1)
.split('\n')
.map((line) => ' '.repeat(4) + line)
.join('\n')}
/> />
); )
};` }`
} }
const EmbedChat = ({ chatflowid }) => { const EmbedChat = ({ chatflowid }) => {
@@ -341,7 +324,7 @@ const EmbedChat = ({ chatflowid }) => {
case 'Fullpage React': case 'Fullpage React':
return embedFullpageReactCodeCustomization(chatflowid) return embedFullpageReactCodeCustomization(chatflowid)
default: default:
return '' return embedPopupHtmlCodeCustomization(chatflowid)
} }
} }