Skip to content

Commit

Permalink
3.0.0-Beta-11 移除环境变量依赖
Browse files Browse the repository at this point in the history
- 移除环境变量依赖
  • Loading branch information
atorber committed Mar 18, 2024
1 parent 4db935d commit d9f145e
Show file tree
Hide file tree
Showing 17 changed files with 329 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ADMINROOM_ADMINROOMTOPIC="替换为你的管理员群名称" # 管理群名称
VIKA_SPACE_ID="替换为你的维格表空间ID" # 维格表空间ID或飞书多维表格的appToken
VIKA_TOKEN="替换为你的维格表token" # 维格表token或飞书多维表格信息拼接(使用'/'拼接三个参数:appId/appSecret/appToken)
ENDPOINT="http://127.0.0.1:9503" # 后端管理服务API地址,默认http://127.0.0.1:9503

# ENDPOINT="http://120.48.99.192:9503" # 官方体验环境地址,可以直接使用,不需要启动chatflow-admin,但服务器不定时重启,不保证稳定

# --------------------------------分割线--------------------------------
# 以下配置无需关注,功能实现中,暂未使用,仅需要配置分割线以上的配置即可
Expand Down
41 changes: 33 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,28 @@ ChatFlow是一个聊天机器人管理系统,可以帮助你实现一些原生

> 升级代码后建议配置全新的维格表空间或删除原空间全部表,请使用nodejs16或18,最新的nodejs20可能无法运行
1.下载源码并安装依赖
最新部署方法参考:[ChatFlow3.0Beta部署运行](https://www.yuque.com/atorber/chatflow/gbpvgf01cw0nlxu4)

1.下载代码及安装启动

1.1 下载并运行chatflow-admin

```Shell
git clone <https://github.com/atorber/chatflow.git>
cd ./chatflow
npm install
git clone https://github.com/atorber/chatflow-admin.git
cd chatflow-admin

# 安装依赖
npm i

# 启动api服务
npm run start:dev
```

1.2 下载并运行chatflow

```Shell
git clone https://github.com/atorber/chatflow.git
cd chatflow
```

2.分别登陆[微信对话开放平台](https://openai.weixin.qq.com/)[vika维格表](https://spcp52tvpjhxm.com.vika.cn/?inviteCode=55152973)官网注册账号并获取token
Expand All @@ -53,12 +69,17 @@ npm install
> 快速开始仅需要修改VIKA_TOKEN、VIKA_SPACE_NAME、ADMINROOM_ADMINROOMTOPIC配置项,其他配置项暂时无需修改,使用微信对话开放平台时配置WXOPENAI_TOKEN、WXOPENAI_ENCODINGAESKEY
```.env
# 维格表配置
VIKA_SPACE_ID="替换为自己的维格表空间ID"
VIKA_TOKEN="替换为自己的维格表token"
# Wechaty
WECHATY_PUPPET="wechaty-puppet-wechat4u" # 可选值:wechaty-puppet-wechat4u、wechaty-puppet-wechat、wechaty-puppet-xp、wechaty-puppet-engine、wechaty-puppet-padlocal、wechaty-puppet-service
WECHATY_TOKEN="" # 使用wechaty-puppet-padlocal、wechaty-puppet-service时需配置此token
# 基础配置
ADMINROOM_ADMINROOMTOPIC="瓦力是群主" # 管理群名称,需尽量保持名称复杂,避免重名群干扰
ADMINROOM_ADMINROOMTOPIC="替换为你的管理员群名称" # 管理群名称,需尽量保持名称复杂,避免重名群干扰
# 维格表配置
VIKA_SPACE_ID="替换为你的维格表空间ID" # 维格表空间ID或飞书多维表格的appToken
VIKA_TOKEN="替换为你的维格表token" # 维格表token或飞书多维表格信息拼接(使用'/'拼接三个参数:appId/appSecret/appToken)
ENDPOINT="http://127.0.0.1:9503" # 后端管理服务API地址,默认http://127.0.0.1:9503
```

4.启动程序
Expand Down Expand Up @@ -172,6 +193,10 @@ atorber/chatflow:latest

## 更新日志

### 3.0.0-Beta-11

- 移除环境变量依赖

### 3.0.0-Beta-10

- 新增媒体资源接口
Expand Down
24 changes: 0 additions & 24 deletions example/ding-dong-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import {
ChatFlow,
getBotOps,
logForm,
// LarkDB,
GroupMaster,
GroupMasterConfig,
init,
} from '../src/index.js'

Expand All @@ -38,27 +35,6 @@ const main = async () => {
logForm('初始化检查失败:' + JSON.stringify(e))
}

// 使用Lark
// await LarkDB.init({
// appId: process.env['LARK_APP_ID'],
// appSecret: process.env['LARK_APP_SECRET'],
// appToken: process.env['LARK_BITABLE_APP_TOKEN'],
// userMobile: process.env['LARK_APP_USER_MOBILE'],
// })

// 如果配置了群管理秘书,则启动群管理秘书,这是一个探索性功能,暂未开放,可以忽略
if (process.env['GROUP_MASTER_ENDPOINT']) {
const configGroupMaster: GroupMasterConfig = {
WX_KEY:process.env['GROUP_MASTER_WX_KEY'] || '',
MQTT_ENDPOINT:process.env['GROUP_MASTER_MQTT_ENDPOINT'] || '',
MQTT_USERNAME:process.env['GROUP_MASTER_MQTT_USERNAME'] || '',
MQTT_PASSWORD:process.env['GROUP_MASTER_MQTT_PASSWORD'] || '',
MQTT_PORT:Number(process.env['GROUP_MASTER_MQTT_PORT'] || '1883'),
HOST:process.env['GROUP_MASTER_ENDPOINT'] || '',
}
bot.use(GroupMaster(configGroupMaster))
}

// 启用ChatFlow插件
bot.use(ChatFlow({
spaceId: VIKA_SPACE_ID,
Expand Down
18 changes: 12 additions & 6 deletions example/group-master-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ const main = async () => {

const puppet = process.env['WECHATY_PUPPET']
const token = process.env['WECHATY_TOKEN']
const WX_KEY = process.env['GROUP_MASTER_WX_KEY'] || ''
const MQTT_ENDPOINT = process.env['GROUP_MASTER_MQTT_ENDPOINT'] || ''
const MQTT_USERNAME = process.env['GROUP_MASTER_MQTT_USERNAME'] || ''
const MQTT_PASSWORD = process.env['GROUP_MASTER_MQTT_PASSWORD'] || ''
const MQTT_PORT = Number(process.env['GROUP_MASTER_MQTT_PORT'] || '1883')
const HOST = process.env['GROUP_MASTER_ENDPOINT'] || ''

const config: GroupMasterConfig = {
WX_KEY:process.env['GROUP_MASTER_WX_KEY'] || '',
MQTT_ENDPOINT:process.env['GROUP_MASTER_MQTT_ENDPOINT'] || '',
MQTT_USERNAME:process.env['GROUP_MASTER_MQTT_USERNAME'] || '',
MQTT_PASSWORD:process.env['GROUP_MASTER_MQTT_PASSWORD'] || '',
MQTT_PORT:Number(process.env['GROUP_MASTER_MQTT_PORT'] || '1883'),
HOST:process.env['GROUP_MASTER_ENDPOINT'] || '',
WX_KEY,
MQTT_ENDPOINT,
MQTT_USERNAME,
MQTT_PASSWORD,
MQTT_PORT,
HOST,
}
// 构建机器人
const ops = getBotOps(puppet, token)
Expand Down
26 changes: 0 additions & 26 deletions example/init-db.ts

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atorber/chatflow",
"version": "3.0.0-Beta-10",
"version": "3.0.0-Beta-11",
"description": "ChatFlow-聊天机器人管理平台",
"type": "module",
"exports": {
Expand Down Expand Up @@ -108,7 +108,8 @@
"typescript": "^4.9.3",
"wechaty": "^1.20.2",
"wechaty-puppet-padlocal": "^1.20.1",
"wechaty-puppet-wechat4u": "^1.14.12"
"wechaty-puppet-wechat4u": "^1.14.12",
"wechaty-puppet-xp": "^1.13.8"
},
"files": [
"bin/",
Expand Down
42 changes: 42 additions & 0 deletions src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,48 @@ export const adminAction = async (message:Message) => {
const tableName = ChatFlowConfig.db.dataBaseNames[tableCode as keyof typeof ChatFlowConfig.db.dataBaseNames]
log.info('数据表名称:', tableName)
await message.say(`检测到多维表格链接,表格名称:【${tableName}】,\n是否需要处理?\n配置信息:\n${JSON.stringify(config, null, 2)}`)

switch (tableCode) {
case 'mediaSheet':
await ChatFlowConfig.updateMediaList()
break
case 'envSheet':
await ChatFlowConfig.updateEnv()
break
case 'groupSheet':
await ChatFlowConfig.updateGroup()
break
case 'chatBotUserSheet':
await ChatFlowConfig.updateChatBotUser()
break
case 'chatBotSheet':
await ChatFlowConfig.updateChatBot()
break
case 'whiteListSheet':
await ChatFlowConfig.updateWhiteList()
break
case 'groupNoticeSheet':
await ChatFlowConfig.updateGroupNotifications()
break
case 'statisticSheet':
await ChatFlowConfig.updateStatistics()
break
case 'noticeSheet':
await ChatFlowConfig.updateReminder()
break
case 'qaSheet':
await ChatFlowConfig.updateQaList()
break
case 'keywordSheet':
await ChatFlowConfig.updateKeywords()
break
case 'welcomeSheet':
await ChatFlowConfig.updateWelcomes()
break
default:
log.info('多维表格配置信息不需要处理...')
}

} else {
log.info('多维表格配置信息不匹配,不处理...')
await message.say(`检测到多维表格链接,但不是当前系统的多维表格链接,不处理~\n配置信息:\n${JSON.stringify(config, null, 2)}`)
Expand Down
Loading

0 comments on commit d9f145e

Please sign in to comment.