@@ -53,7 +53,10 @@ const embedPopupReactCode = (chatflowid) => {
53
53
54
54
const App = () => {
55
55
return (
56
- <BubbleChat chatflowid="${ chatflowid } " apiHost="${ baseURL } " />
56
+ <BubbleChat
57
+ chatflowid="${ chatflowid } "
58
+ apiHost="${ baseURL } "
59
+ />
57
60
);
58
61
};`
59
62
}
@@ -82,158 +85,110 @@ const App = () => {
82
85
};`
83
86
}
84
87
85
- const buttonConfig = ( isReact = false ) => {
86
- return isReact
87
- ? `button: {
88
- backgroundColor: "#3B81F6",
89
- right: 20,
90
- bottom: 20,
91
- size: 48, // small | medium | large | number
92
- dragAndDrop: true,
93
- iconColor: "white",
94
- customIconSrc: "https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg",
95
- autoWindowOpen: {
96
- autoOpen: true, //parameter to control automatic window opening
97
- openDelay: 2, // Optional parameter for delay time in seconds
98
- autoOpenOnMobile: false, //parameter to control automatic window opening in mobile
99
- },
100
- }`
101
- : `button: {
102
- backgroundColor: "#3B81F6",
103
- right: 20,
104
- bottom: 20,
105
- size: 48, // small | medium | large | number
106
- dragAndDrop: true,
107
- iconColor: "white",
108
- customIconSrc: "https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg",
109
- autoWindowOpen: {
110
- autoOpen: true, //parameter to control automatic window opening
111
- openDelay: 2, // Optional parameter for delay time in seconds
112
- autoOpenOnMobile: false, //parameter to control automatic window opening in mobile
113
- },
114
- }`
115
- }
116
-
117
- const tooltipConfig = ( isReact = false ) => {
118
- return isReact
119
- ? `tooltip: {
120
- showTooltip: true,
121
- tooltipMessage: 'Hi There 👋!',
122
- tooltipBackgroundColor: 'black',
123
- tooltipTextColor: 'white',
124
- tooltipFontSize: 16,
125
- }`
126
- : `tooltip: {
127
- showTooltip: true,
128
- tooltipMessage: 'Hi There 👋!',
129
- tooltipBackgroundColor: 'black',
130
- tooltipTextColor: 'white',
131
- tooltipFontSize: 16,
132
- }`
88
+ export const defaultThemeConfig = {
89
+ button : {
90
+ backgroundColor : '#3B81F6' ,
91
+ right : 20 ,
92
+ bottom : 20 ,
93
+ size : 48 ,
94
+ dragAndDrop : true ,
95
+ iconColor : 'white' ,
96
+ customIconSrc : 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg' ,
97
+ autoWindowOpen : {
98
+ autoOpen : true ,
99
+ openDelay : 2 ,
100
+ autoOpenOnMobile : false
101
+ }
102
+ } ,
103
+ tooltip : {
104
+ showTooltip : true ,
105
+ tooltipMessage : 'Hi There 👋!' ,
106
+ tooltipBackgroundColor : 'black' ,
107
+ tooltipTextColor : 'white' ,
108
+ tooltipFontSize : 16
109
+ } ,
110
+ disclaimer : {
111
+ title : 'Disclaimer' ,
112
+ message : 'By using this chatbot, you agree to the <a target="_blank" href="https://flowiseai.com/terms">Terms & Condition</a>' ,
113
+ textColor : 'black' ,
114
+ buttonColor : '#3b82f6' ,
115
+ buttonText : 'Start Chatting' ,
116
+ buttonTextColor : 'white' ,
117
+ blurredBackgroundColor : 'rgba(0, 0, 0, 0.4)' ,
118
+ backgroundColor : 'white'
119
+ } ,
120
+ customCSS : `` ,
121
+ chatWindow : {
122
+ showTitle : true ,
123
+ showAgentMessages : true ,
124
+ title : 'Flowise Bot' ,
125
+ titleAvatarSrc : 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg' ,
126
+ welcomeMessage : 'Hello! This is custom welcome message' ,
127
+ errorMessage : 'This is a custom error message' ,
128
+ backgroundColor : '#ffffff' ,
129
+ backgroundImage : 'enter image path or link' ,
130
+ height : 700 ,
131
+ width : 400 ,
132
+ fontSize : 16 ,
133
+ starterPrompts : [ 'What is a bot?' , 'Who are you?' ] ,
134
+ starterPromptFontSize : 15 ,
135
+ clearChatOnReload : false ,
136
+ sourceDocsTitle : 'Sources:' ,
137
+ renderHTML : true ,
138
+ botMessage : {
139
+ backgroundColor : '#f7f8ff' ,
140
+ textColor : '#303235' ,
141
+ showAvatar : true ,
142
+ avatarSrc : 'https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png'
143
+ } ,
144
+ userMessage : {
145
+ backgroundColor : '#3B81F6' ,
146
+ textColor : '#ffffff' ,
147
+ showAvatar : true ,
148
+ avatarSrc : 'https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png'
149
+ } ,
150
+ textInput : {
151
+ placeholder : 'Type your question' ,
152
+ backgroundColor : '#ffffff' ,
153
+ textColor : '#303235' ,
154
+ sendButtonColor : '#3B81F6' ,
155
+ maxChars : 50 ,
156
+ maxCharsWarningMessage : 'You exceeded the characters limit. Please input less than 50 characters.' ,
157
+ autoFocus : true ,
158
+ sendMessageSound : true ,
159
+ sendSoundLocation : 'send_message.mp3' ,
160
+ receiveMessageSound : true ,
161
+ receiveSoundLocation : 'receive_message.mp3'
162
+ } ,
163
+ feedback : {
164
+ color : '#303235'
165
+ } ,
166
+ dateTimeToggle : {
167
+ date : true ,
168
+ time : true
169
+ } ,
170
+ footer : {
171
+ textColor : '#303235' ,
172
+ text : 'Powered by' ,
173
+ company : 'Flowise' ,
174
+ companyLink : 'https://flowiseai.com'
175
+ }
176
+ }
133
177
}
134
178
135
- const chatwindowConfig = ( isReact = false ) => {
136
- return isReact
137
- ? `chatWindow: {
138
- showTitle: true,
139
- title: 'Flowise Bot',
140
- titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
141
- showAgentMessages: true,
142
- welcomeMessage: 'Hello! This is custom welcome message',
143
- errorMessage: 'This is a custom error message',
144
- backgroundColor: "#ffffff",
145
- backgroundImage: 'enter image path or link', // If set, this will overlap the background color of the chat window.
146
- height: 700,
147
- width: 400,
148
- fontSize: 16,
149
- //starterPrompts: ['What is a bot?', 'Who are you?'], // It overrides the starter prompts set by the chat flow passed
150
- starterPromptFontSize: 15,
151
- clearChatOnReload: false, // If set to true, the chat will be cleared when the page reloads.
152
- botMessage: {
153
- backgroundColor: "#f7f8ff",
154
- textColor: "#303235",
155
- showAvatar: true,
156
- avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png",
157
- },
158
- userMessage: {
159
- backgroundColor: "#3B81F6",
160
- textColor: "#ffffff",
161
- showAvatar: true,
162
- avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png",
163
- },
164
- textInput: {
165
- placeholder: 'Type your question',
166
- backgroundColor: '#ffffff',
167
- textColor: '#303235',
168
- sendButtonColor: '#3B81F6',
169
- maxChars: 50,
170
- maxCharsWarningMessage: 'You exceeded the characters limit. Please input less than 50 characters.',
171
- autoFocus: true, // If not used, autofocus is disabled on mobile and enabled on desktop. true enables it on both, false disables it on both.
172
- sendMessageSound: true,
173
- // sendSoundLocation: "send_message.mp3", // If this is not used, the default sound effect will be played if sendSoundMessage is true.
174
- receiveMessageSound: true,
175
- // receiveSoundLocation: "receive_message.mp3", // If this is not used, the default sound effect will be played if receiveSoundMessage is true.
176
- },
177
- feedback: {
178
- color: '#303235',
179
- },
180
- footer: {
181
- textColor: '#303235',
182
- text: 'Powered by',
183
- company: 'Flowise',
184
- companyLink: 'https://flowiseai.com',
185
- }
186
- }`
187
- : `chatWindow: {
188
- showTitle: true,
189
- title: 'Flowise Bot',
190
- titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
191
- showAgentMessages: true,
192
- welcomeMessage: 'Hello! This is custom welcome message',
193
- errorMessage: 'This is a custom error message',
194
- backgroundColor: "#ffffff",
195
- backgroundImage: 'enter image path or link', // If set, this will overlap the background color of the chat window.
196
- height: 700,
197
- width: 400,
198
- fontSize: 16,
199
- //starterPrompts: ['What is a bot?', 'Who are you?'], // It overrides the starter prompts set by the chat flow passed
200
- starterPromptFontSize: 15,
201
- clearChatOnReload: false, // If set to true, the chat will be cleared when the page reloads.
202
- botMessage: {
203
- backgroundColor: "#f7f8ff",
204
- textColor: "#303235",
205
- showAvatar: true,
206
- avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png",
207
- },
208
- userMessage: {
209
- backgroundColor: "#3B81F6",
210
- textColor: "#ffffff",
211
- showAvatar: true,
212
- avatarSrc: "https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png",
213
- },
214
- textInput: {
215
- placeholder: 'Type your question',
216
- backgroundColor: '#ffffff',
217
- textColor: '#303235',
218
- sendButtonColor: '#3B81F6',
219
- maxChars: 50,
220
- maxCharsWarningMessage: 'You exceeded the characters limit. Please input less than 50 characters.',
221
- autoFocus: true, // If not used, autofocus is disabled on mobile and enabled on desktop. true enables it on both, false disables it on both.
222
- sendMessageSound: true,
223
- // sendSoundLocation: "send_message.mp3", // If this is not used, the default sound effect will be played if sendSoundMessage is true.
224
- receiveMessageSound: true,
225
- // receiveSoundLocation: "receive_message.mp3", // If this is not used, the default sound effect will be played if receiveSoundMessage is true.
226
- },
227
- feedback: {
228
- color: '#303235',
229
- },
230
- footer: {
231
- textColor: '#303235',
232
- text: 'Powered by',
233
- company: 'Flowise',
234
- companyLink: 'https://flowiseai.com',
235
- }
236
- }`
179
+ const customStringify = ( obj ) => {
180
+ let stringified = JSON . stringify ( obj , null , 4 )
181
+ . replace ( / " ( [ ^ " ] + ) " : / g, '$1:' )
182
+ . replace ( / : " ( [ ^ " ] + ) " / g, ( match , value ) => ( value . includes ( '<' ) ? `: "${ value } "` : `: '${ value } '` ) )
183
+ . replace ( / : " ( t r u e | f a l s e | \d + ) " / g, ': $1' )
184
+ . replace ( / c u s t o m C S S : " " / g, 'customCSS: ``' )
185
+ return stringified
186
+ . split ( '\n' )
187
+ . map ( ( line , index ) => {
188
+ if ( index === 0 ) return line
189
+ return ' ' . repeat ( 8 ) + line
190
+ } )
191
+ . join ( '\n' )
237
192
}
238
193
239
194
const embedPopupHtmlCodeCustomization = ( chatflowid ) => {
@@ -243,13 +198,12 @@ const embedPopupHtmlCodeCustomization = (chatflowid) => {
243
198
chatflowid: "${ chatflowid } ",
244
199
apiHost: "${ baseURL } ",
245
200
chatflowConfig: {
246
- // topK: 2
201
+ /* Chatflow Config */
247
202
},
248
- theme: {
249
- ${ buttonConfig ( ) } ,
250
- ${ tooltipConfig ( ) } ,
251
- ${ chatwindowConfig ( ) }
252
- }
203
+ observersConfig: {
204
+ /* Observers Config */
205
+ },
206
+ theme: ${ customStringify ( defaultThemeConfig ) }
253
207
})
254
208
</script>`
255
209
}
@@ -262,14 +216,31 @@ const App = () => {
262
216
<BubbleChat
263
217
chatflowid="${ chatflowid } "
264
218
apiHost="${ baseURL } "
265
- theme={{
266
- ${ buttonConfig ( true ) } ,
267
- ${ tooltipConfig ( true ) } ,
268
- ${ chatwindowConfig ( true ) }
219
+ chatflowConfig={{
220
+ /* Chatflow Config */
269
221
}}
222
+ observersConfig={{
223
+ /* Observers Config */
224
+ }}
225
+ theme={{${ customStringify ( defaultThemeConfig )
226
+ . substring ( 1 )
227
+ . split ( '\n' )
228
+ . map ( ( line ) => ' ' . repeat ( 4 ) + line )
229
+ . join ( '\n' ) }
270
230
/>
271
- );
272
- };`
231
+ )
232
+ }`
233
+ }
234
+
235
+ const getFullPageThemeConfig = ( ) => {
236
+ return {
237
+ ...defaultThemeConfig ,
238
+ chatWindow : {
239
+ ...defaultThemeConfig . chatWindow ,
240
+ height : '100%' ,
241
+ width : '100%'
242
+ }
243
+ }
273
244
}
274
245
275
246
const embedFullpageHtmlCodeCustomization = ( chatflowid ) => {
@@ -279,27 +250,39 @@ const embedFullpageHtmlCodeCustomization = (chatflowid) => {
279
250
Chatbot.initFull({
280
251
chatflowid: "${ chatflowid } ",
281
252
apiHost: "${ baseURL } ",
282
- theme: {
283
- ${ chatwindowConfig ( ) }
284
- }
253
+ chatflowConfig: {
254
+ /* Chatflow Config */
255
+ },
256
+ observersConfig: {
257
+ /* Observers Config */
258
+ },
259
+ theme: ${ customStringify ( getFullPageThemeConfig ( ) ) }
285
260
})
286
261
</script>`
287
262
}
288
263
289
264
const embedFullpageReactCodeCustomization = ( chatflowid ) => {
290
- return `import { FullPageChat } from " flowise-embed-react"
265
+ return `import { FullPageChat } from ' flowise-embed-react'
291
266
292
267
const App = () => {
293
268
return (
294
269
<FullPageChat
295
270
chatflowid="${ chatflowid } "
296
271
apiHost="${ baseURL } "
297
- theme ={{
298
- ${ chatwindowConfig ( true ) }
272
+ chatflowConfig ={{
273
+ /* Chatflow Config */
299
274
}}
275
+ observersConfig={{
276
+ /* Observers Config */
277
+ }}
278
+ theme={{${ customStringify ( getFullPageThemeConfig ( ) )
279
+ . substring ( 1 )
280
+ . split ( '\n' )
281
+ . map ( ( line ) => ' ' . repeat ( 4 ) + line )
282
+ . join ( '\n' ) }
300
283
/>
301
- );
302
- }; `
284
+ )
285
+ }`
303
286
}
304
287
305
288
const EmbedChat = ( { chatflowid } ) => {
@@ -341,7 +324,7 @@ const EmbedChat = ({ chatflowid }) => {
341
324
case 'Fullpage React' :
342
325
return embedFullpageReactCodeCustomization ( chatflowid )
343
326
default :
344
- return ''
327
+ return embedPopupHtmlCodeCustomization ( chatflowid )
345
328
}
346
329
}
347
330
0 commit comments