diff --git a/components/Coze.js b/components/Coze.js new file mode 100644 index 00000000..d4472d29 --- /dev/null +++ b/components/Coze.js @@ -0,0 +1,39 @@ +import { siteConfig } from '@/lib/config' +import { loadExternalResource } from '@/lib/utils' +import { useEffect } from 'react' + +/** + * Coze-AI机器人 + * @returns + */ +export default function Coze() { + const cozeSrc = siteConfig( + 'COZE_SRC_URL', + 'https://lf-cdn.coze.cn/obj/unpkg/flow-platform/chat-app-sdk/0.1.0-beta.6/libs/cn/index.js' + ) + const title = siteConfig('COZE_TITLE', 'NotionNext助手') + const botId = siteConfig('COZE_BOT_ID') + + const loadCoze = async () => { + await loadExternalResource(cozeSrc) + CozeWebSDK = window.CozeWebSDK + if (CozeWebSDK) { + new CozeWebSDK.WebChatClient({ + config: { + bot_id: botId + }, + componentProps: { + title: title + } + }) + } + } + + useEffect(() => { + if (!botId) { + return + } + loadCoze() + }, []) + return <> +} diff --git a/components/ExternalPlugins.js b/components/ExternalPlugins.js index d798a940..772f8b00 100644 --- a/components/ExternalPlugins.js +++ b/components/ExternalPlugins.js @@ -9,6 +9,7 @@ import { convertInnerUrl } from '@/lib/notion/convertInnerUrl' import { isBrowser, loadExternalResource } from '@/lib/utils' import { useRouter } from 'next/router' import { useEffect } from 'react' +import Coze from './Coze' import { initGoogleAdsense } from './GoogleAdsense' /** @@ -65,6 +66,7 @@ const ExternalPlugin = props => { const CUSTOM_EXTERNAL_JS = siteConfig('CUSTOM_EXTERNAL_JS') // 默认关闭NProgress const ENABLE_NPROGRSS = siteConfig('ENABLE_NPROGRSS', false) + const COZE_BOT_ID = siteConfig('COZE_BOT_ID') // 自定义样式css和js引入 if (isBrowser) { @@ -150,6 +152,7 @@ const ExternalPlugin = props => { {ENABLE_NPROGRSS && } {ANALYTICS_51LA_ID && ANALYTICS_51LA_CK && } + {COZE_BOT_ID && } {ANALYTICS_51LA_ID && ANALYTICS_51LA_CK && ( <>