Skip to content

Coze官方升级需要鉴权才能使用,另外Coze_bot_id部分整数长度超过了JavaScript整数安全长度,导致id后三位从Notion Config读过来变为000 #3242

Open
@kyeo-hub

Description

描述bug
Coze官方升级需要鉴权才能使用,否则报错。

期望的正常结果
已经修改Coze.js文件,不再报错,但是不知道怎么修复Coze bot id过长的问题,否则我的id只能暴露在源代码中使用。

复现步骤
修改./components/Coze.js文件如下

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'         //需要更新,或者在notion config里面去更新最新的sdk
  )
  const title = siteConfig('COZE_TITLE', 'NotionNext助手')
  const botId = siteConfig('COZE_BOT_ID')
  const loadCoze = async () => {
    await loadExternalResource(cozeSrc)
    const CozeWebSDK = window?.CozeWebSDK
    if (CozeWebSDK) {
      const cozeClient = new CozeWebSDK.WebChatClient({
        config: {
          bot_id: botId                    //此处的botId带入过来的时候,最后几位会变成0,是因为超过了JavaScript的整数安全限制,我试过修改源代码的siteConfig函数,但是不得要领,手动在此改为coze_bot_id就没有问题。
        },
       //下面的部分是鉴权部分,
        auth: {
          type: 'token',
          token: 'pat_cjj94P7jJP*************fjFUIipuxCC*********',
          onRefreshToken: async () => 'pat_cjj94P7jJP*************fjFUIipuxCC************',
        },
        userInfo: {
          id: 'user',
          url: 'https://kyeo.top/assets/images/0.png',
          nickname: 'UserA',
        },
        ui: {
          base: {
            icon: 'https://kyeo.top/assets/images/0.png',
            layout: 'pc',
            lang: 'en',
            zIndex: 1000,
          },
          chatBot: {
            title: title,
            uploadable: true,
            width: 300
          },
          asstBtn: {
            isNeed: true,
          },
          footer: {
            isShow: true,
            expressionText: 'Powered by & 集家嘴的壳玛🐸',
            linkvars: {
              name: {
                text: 'A',
                link: 'https://www.test1.com'
              },
              name1: {
                text: 'B',
                link: 'https://www.test2.com'
              }
            }
          }
        }

      })
      console.log('coze', cozeClient)
    }
  }

  useEffect(() => {
    if (!botId) {
      return
    }
    loadCoze()
  }, [])
  return <></>
}

环境

  • 【必填】NotionNext版本 [4.8.3]
  • 【必填】主题 [gitbook]
  • 【必填】部署方案 [docker]
  • 【可选】操作系统: [windows]
  • 【可选】浏览器 [edge]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions