From d5fe50e47104a39cbf0a1f14b2dd9168d03f1c09 Mon Sep 17 00:00:00 2001 From: "Junjie.M" <118170653@qq.com> Date: Wed, 23 Apr 2025 16:48:45 +0800 Subject: [PATCH] embedding in websites support initializes to specify the conversation_id (#18602) --- web/app/components/app/overview/embedded/index.tsx | 1 + web/app/components/base/chat/embedded-chatbot/hooks.tsx | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/web/app/components/app/overview/embedded/index.tsx b/web/app/components/app/overview/embedded/index.tsx index d4e5dd8898..6ebd0fce69 100644 --- a/web/app/components/app/overview/embedded/index.tsx +++ b/web/app/components/app/overview/embedded/index.tsx @@ -48,6 +48,7 @@ const OPTION_MAP = { : ''}, systemVariables: { // user_id: 'YOU CAN DEFINE USER ID HERE', + // conversation_id: 'YOU CAN DEFINE CONVERSATION ID HERE, IT MUST BE A VALID UUID', }, } diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 0f2529152c..cfd2acb17f 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -73,9 +73,11 @@ export const useEmbeddedChatbot = () => { const appId = useMemo(() => appData?.app_id, [appData]) const [userId, setUserId] = useState() + const [conversationId, setConversationId] = useState() useEffect(() => { - getProcessedSystemVariablesFromUrlParams().then(({ user_id }) => { + getProcessedSystemVariablesFromUrlParams().then(({ user_id, conversation_id }) => { setUserId(user_id) + setConversationId(conversation_id) }) }, []) @@ -109,7 +111,8 @@ export const useEmbeddedChatbot = () => { const [conversationIdInfo, setConversationIdInfo] = useLocalStorageState>>(CONVERSATION_ID_INFO, { defaultValue: {}, }) - const currentConversationId = useMemo(() => conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || '', [appId, conversationIdInfo, userId]) + const currentConversationId = useMemo(() => conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || conversationId || '', + [appId, conversationIdInfo, userId, conversationId]) const handleConversationIdInfoChange = useCallback((changeConversationId: string) => { if (appId) { let prevValue = conversationIdInfo?.[appId || '']