Skip to content

Commit

Permalink
CozeAI
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Sep 20, 2024
1 parent 8332e97 commit eb1d46d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions components/Coze.js
Original file line number Diff line number Diff line change
@@ -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 <></>
}
3 changes: 3 additions & 0 deletions components/ExternalPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -150,6 +152,7 @@ const ExternalPlugin = props => {
{ENABLE_NPROGRSS && <LoadingProgress />}
<AosAnimation />
{ANALYTICS_51LA_ID && ANALYTICS_51LA_CK && <LA51 />}
{COZE_BOT_ID && <Coze />}

{ANALYTICS_51LA_ID && ANALYTICS_51LA_CK && (
<>
Expand Down

0 comments on commit eb1d46d

Please sign in to comment.