Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: define a custom error message for allowed domains #2194

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 9.0.3
version: 9.0.4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"turbo": "1.10.16",
"typescript": "^4.8.4"
},
"packageManager": "[email protected].3",
"packageManager": "[email protected].4",
"pnpm": {
"onlyBuiltDependencies": [
"faiss-node",
Expand Down
62 changes: 51 additions & 11 deletions packages/ui/src/ui-component/extended/AllowedDomains.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import PropTypes from 'prop-types'
import { enqueueSnackbar as enqueueSnackbarAction, closeSnackbar as closeSnackbarAction, SET_CHATFLOW } from '@/store/actions'

// material-ui
import { Button, IconButton, OutlinedInput, Box, List, InputAdornment } from '@mui/material'
import { Button, IconButton, OutlinedInput, Box, List, InputAdornment, Typography } from '@mui/material'
import { IconX, IconTrash, IconPlus } from '@tabler/icons'

// Project import
import { StyledButton } from '@/ui-component/button/StyledButton'
import { TooltipWithParser } from '@/ui-component/tooltip/TooltipWithParser'

// store
import useNotifier from '@/utils/useNotifier'
Expand All @@ -25,6 +26,7 @@ const AllowedDomains = ({ dialogProps }) => {
const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args))

const [inputFields, setInputFields] = useState([''])
const [errorMessage, setErrorMessage] = useState('')

const [chatbotConfig, setChatbotConfig] = useState({})

Expand All @@ -47,9 +49,12 @@ const AllowedDomains = ({ dialogProps }) => {
const onSave = async () => {
try {
let value = {
allowedOrigins: [...inputFields]
allowedOrigins: [...inputFields],
allowedOriginsError: errorMessage
}
chatbotConfig.allowedOrigins = value.allowedOrigins
chatbotConfig.allowedOriginsError = value.allowedOriginsError

const saveResp = await chatflowsApi.updateChatflow(dialogProps.chatflow.id, {
chatbotConfig: JSON.stringify(chatbotConfig)
})
Expand Down Expand Up @@ -98,8 +103,14 @@ const AllowedDomains = ({ dialogProps }) => {
} else {
setInputFields([''])
}
if (chatbotConfig.allowedOriginsError) {
setErrorMessage(chatbotConfig.allowedOriginsError)
} else {
setErrorMessage('')
}
} catch (e) {
setInputFields([''])
setErrorMessage('')
}
}

Expand All @@ -108,15 +119,21 @@ const AllowedDomains = ({ dialogProps }) => {

return (
<>
<div
style={{
display: 'flex',
flexDirection: 'column'
}}
>
<span>Your chatbot will only work when used from the following domains.</span>
</div>
<Box sx={{ '& > :not(style)': { m: 1 }, pt: 2 }}>
<Box>
<Box
sx={{
display: 'flex',
flexDirection: 'column'
}}
>
<Typography sx={{ mb: 1 }}>
Allowed Domains
<TooltipWithParser
style={{ mb: 1, mt: 2, marginLeft: 10 }}
title={'Your chatbot will only work when used from the following domains.'}
/>
</Typography>
</Box>
<List>
{inputFields.map((origin, index) => {
return (
Expand All @@ -130,6 +147,7 @@ const AllowedDomains = ({ dialogProps }) => {
size='small'
value={origin}
name='origin'
placeholder='https://example.com'
endAdornment={
<InputAdornment position='end' sx={{ padding: '2px' }}>
{inputFields.length > 1 && (
Expand Down Expand Up @@ -160,6 +178,28 @@ const AllowedDomains = ({ dialogProps }) => {
})}
</List>
</Box>
<Box sx={{ pt: 2, pb: 2 }}>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
<Typography sx={{ mb: 1 }}>
Error Message
<TooltipWithParser
style={{ mb: 1, mt: 2, marginLeft: 10 }}
title={'Custom error message that will be shown when for unauthorized domain'}
/>
</Typography>
<OutlinedInput
sx={{ width: '100%' }}
type='text'
size='small'
fullWidth
placeholder='Unauthorized domain!'
value={errorMessage}
onChange={(e) => {
setErrorMessage(e.target.value)
}}
/>
</div>
</Box>
<StyledButton variant='contained' onClick={onSave}>
Save
</StyledButton>
Expand Down
9 changes: 5 additions & 4 deletions packages/ui/src/ui-component/extended/RateLimit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Box, Typography, Button, OutlinedInput } from '@mui/material'

// Project import
import { StyledButton } from '@/ui-component/button/StyledButton'
import { TooltipWithParser } from '@/ui-component/tooltip/TooltipWithParser'

// Icons
import { IconX } from '@tabler/icons'
Expand All @@ -16,7 +17,6 @@ import chatflowsApi from '@/api/chatflows'

// utils
import useNotifier from '@/utils/useNotifier'
import { TooltipWithParser } from '@/ui-component/tooltip/TooltipWithParser'

const RateLimit = () => {
const dispatch = useDispatch()
Expand Down Expand Up @@ -117,6 +117,7 @@ const RateLimit = () => {
value={message}
placeholder={placeholder}
name={fieldName}
size='small'
onChange={(e) => {
onTextChanged(e.target.value, fieldName)
}}
Expand All @@ -138,9 +139,9 @@ const RateLimit = () => {
}
/>
</Typography>
{textField(limitMax, 'limitMax', 'Message Limit per Duration', 'number')}
{textField(limitDuration, 'limitDuration', 'Duration in Second', 'number')}
{textField(limitMsg, 'limitMsg', 'Limit Message', 'string')}
{textField(limitMax, 'limitMax', 'Message Limit per Duration', 'number', '5')}
{textField(limitDuration, 'limitDuration', 'Duration in Second', 'number', '60')}
{textField(limitMsg, 'limitMsg', 'Limit Message', 'string', 'You have reached the quota')}

<StyledButton style={{ marginBottom: 10, marginTop: 10 }} variant='contained' onClick={() => onSave()}>
Save Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/ui-component/extended/SpeechToText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const SpeechToText = ({ dialogProps }) => {
Providers
</Typography>
<FormControl fullWidth>
<Select value={selectedProvider} onChange={handleProviderChange}>
<Select size='small' value={selectedProvider} onChange={handleProviderChange}>
<MenuItem value='none'>None</MenuItem>
<MenuItem value='openAIWhisper'>OpenAI Whisper</MenuItem>
<MenuItem value='assemblyAiTranscribe'>Assembly AI</MenuItem>
Expand All @@ -198,7 +198,7 @@ const SpeechToText = ({ dialogProps }) => {
</Box>
{selectedProvider !== 'none' && (
<>
<ListItem style={{ padding: 0, margin: 0 }} alignItems='center'>
<ListItem sx={{ mt: 3 }} alignItems='center'>
<ListItemAvatar>
<div
style={{
Expand Down
6 changes: 6 additions & 0 deletions packages/ui/src/views/chatflows/ShareChatbot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const ShareChatbot = ({ isSessionMemory }) => {
const [titleAvatarSrc, setTitleAvatarSrc] = useState(chatbotConfig?.titleAvatarSrc ?? '')

const [welcomeMessage, setWelcomeMessage] = useState(chatbotConfig?.welcomeMessage ?? '')
const [errorMessage, setErrorMessage] = useState(chatbotConfig?.errorMessage ?? '')
const [backgroundColor, setBackgroundColor] = useState(chatbotConfig?.backgroundColor ?? defaultConfig.backgroundColor)
const [fontSize, setFontSize] = useState(chatbotConfig?.fontSize ?? defaultConfig.fontSize)
const [poweredByTextColor, setPoweredByTextColor] = useState(chatbotConfig?.poweredByTextColor ?? defaultConfig.poweredByTextColor)
Expand Down Expand Up @@ -114,6 +115,7 @@ const ShareChatbot = ({ isSessionMemory }) => {
if (title) obj.title = title
if (titleAvatarSrc) obj.titleAvatarSrc = titleAvatarSrc
if (welcomeMessage) obj.welcomeMessage = welcomeMessage
if (errorMessage) obj.errorMessage = errorMessage
if (backgroundColor) obj.backgroundColor = backgroundColor
if (fontSize) obj.fontSize = fontSize
if (poweredByTextColor) obj.poweredByTextColor = poweredByTextColor
Expand Down Expand Up @@ -268,6 +270,9 @@ const ShareChatbot = ({ isSessionMemory }) => {
case 'welcomeMessage':
setWelcomeMessage(value)
break
case 'errorMessage':
setErrorMessage(value)
break
case 'fontSize':
setFontSize(value)
break
Expand Down Expand Up @@ -417,6 +422,7 @@ const ShareChatbot = ({ isSessionMemory }) => {
`https://raw.githubusercontent.com/FlowiseAI/Flowise/main/assets/FloWiseAI_dark.png`
)}
{textField(welcomeMessage, 'welcomeMessage', 'Welcome Message', 'string', 'Hello! This is custom welcome message')}
{textField(errorMessage, 'errorMessage', 'Error Message', 'string', 'This is custom error message')}
{colorField(backgroundColor, 'backgroundColor', 'Background Color')}
{textField(fontSize, 'fontSize', 'Font Size', 'number')}
{colorField(poweredByTextColor, 'poweredByTextColor', 'PoweredBy TextColor')}
Expand Down
Loading