-
-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from FlowiseAI/feature/FullPageChatbot-and-Re…
…actChatbot Feature/Add full page chatbot and react chatbot
- Loading branch information
Showing
12 changed files
with
924 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
webpack: { | ||
configure: { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.m?js$/, | ||
resolve: { | ||
fullySpecified: false | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { lazy } from 'react' | ||
|
||
// project imports | ||
import Loadable from 'ui-component/loading/Loadable' | ||
import MinimalLayout from 'layout/MinimalLayout' | ||
|
||
// canvas routing | ||
const ChatbotFull = Loadable(lazy(() => import('views/chatbot'))) | ||
|
||
// ==============================|| CANVAS ROUTING ||============================== // | ||
|
||
const ChatbotRoutes = { | ||
path: '/', | ||
element: <MinimalLayout />, | ||
children: [ | ||
{ | ||
path: '/chatbot/:id', | ||
element: <ChatbotFull /> | ||
} | ||
] | ||
} | ||
|
||
export default ChatbotRoutes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useEffect, useState } from 'react' | ||
import { baseURL } from 'store/constant' | ||
import axios from 'axios' | ||
import { FullPageChat } from 'flowise-embed-react' | ||
|
||
// ==============================|| Chatbot ||============================== // | ||
|
||
const fetchChatflow = async ({ chatflowId }) => { | ||
const username = localStorage.getItem('username') | ||
const password = localStorage.getItem('password') | ||
|
||
let chatflow = await axios | ||
.get(`${baseURL}/api/v1/chatflows/${chatflowId}`, { auth: username && password ? { username, password } : undefined }) | ||
.then(async function (response) { | ||
return response.data | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
return chatflow | ||
} | ||
|
||
const ChatbotFull = () => { | ||
const URLpath = document.location.pathname.toString().split('/') | ||
const chatflowId = URLpath[URLpath.length - 1] === 'chatbot' ? '' : URLpath[URLpath.length - 1] | ||
|
||
const [chatflow, setChatflow] = useState(null) | ||
const [chatbotTheme, setChatbotTheme] = useState({}) | ||
|
||
useEffect(() => { | ||
;(async () => { | ||
const fetchData = async () => { | ||
let response = await fetchChatflow({ chatflowId }) | ||
setChatflow(response) | ||
if (response.chatbotConfig) { | ||
try { | ||
setChatbotTheme(JSON.parse(response.chatbotConfig)) | ||
} catch (e) { | ||
console.error(e) | ||
setChatbotTheme({}) | ||
} | ||
} | ||
} | ||
fetchData() | ||
})() | ||
}, [chatflowId]) | ||
|
||
return ( | ||
<> | ||
{!chatflow || chatflow.apikeyid ? ( | ||
<p>Invalid Chatbot</p> | ||
) : ( | ||
<FullPageChat chatflowid={chatflow.id} apiHost={baseURL} theme={{ chatWindow: chatbotTheme }} /> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default ChatbotFull |
Oops, something went wrong.