Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.0-Beta-11 #65

Merged
merged 10 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Wechaty
WECHATY_PUPPET="wechaty-puppet-wechat4u"
WECHATY_TOKEN=""
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="替换为你的管理员群名称" # 管理群名称,需尽量保持名称复杂,避免重名群干扰

# 维格表配置
VIKA_SPACE_NAME="替换为你的维格表空间名称" # 维格表空间名称,与VIKA_SPACE_ID二选一只需要配置一项即可
VIKA_SPACE_ID="替换为你的维格表空间ID" # 维格表空间ID,与VIKA_SPACE_NAME二选一只需要配置一项即可
VIKA_TOKEN="替换为你的维格表token" #维格表token
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,但服务器不定时重启,不保证稳定

# --------------------------------分割线--------------------------------
# 以下配置无需关注,功能实现中,暂未使用,仅需要配置上面的配置即可
# 以下配置无需关注,功能实现中,暂未使用,仅需要配置分割线以上的配置即可


# 飞书多维表格配置
LARK_APP_ID="" # 飞书多维表格应用ID
Expand Down
61 changes: 52 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,30 @@ ChatFlow是一个聊天机器人管理系统,可以帮助你实现一些原生

## 快速开始

> 2.0.25+之后的版本,数据表不兼容,在运行时建议配置全新的维格表空间或删除原空间全部表
> 升级代码后建议配置全新的维格表空间或删除原空间全部表,请使用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-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
npm install
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 @@ -170,6 +191,28 @@ atorber/chatflow:latest

将过去复杂的IT数据库技术,做得像表格一样简单(如果要注册,通过这个链接,或者使用邀请码 55152973 )

## 更新日志

### 3.0.0-Beta-11

- 移除环境变量依赖

### 3.0.0-Beta-10

- 新增媒体资源接口
- 新增进群欢迎语接口
- 新增顺风车接口

### 3.0.0-6

- 全部接口切换到chatfow-admin,更加稳定可靠
- 修复微信对话开放平台bug
- 增加ChatGPT支持

### 3.0.0-5

- 适配飞书多维表格,初步测试通过

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=atorber/chatflow&type=Date)](https://star-history.com/#atorber/chatflow&Date)
63 changes: 27 additions & 36 deletions example/ding-dong-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,44 @@ import {
import {
ChatFlow,
getBotOps,
log,
logForm,
// LarkDB,
GroupMaster,
GroupMasterConfig,
init,
} from '../src/chatflow.js'
} from '../src/index.js'

const main = async () => {
// 构建机器人
const puppet = process.env['WECHATY_PUPPET']
const token = process.env['WECHATY_TOKEN']

const ops = getBotOps(puppet, token)
// 从环境变量中获取配置信息, 在环境变量中已经配置了以下信息或者直接赋值
const WECHATY_PUPPET = process.env['WECHATY_PUPPET']
const WECHATY_TOKEN = process.env['WECHATY_TOKEN']
const VIKA_SPACE_ID = process.env['VIKA_SPACE_ID']
const VIKA_TOKEN = process.env['VIKA_TOKEN']
const ADMINROOM_ADMINROOMTOPIC = process.env['ADMINROOM_ADMINROOMTOPIC'] // 管理群的topic,可选

// 构建wechaty机器人
const ops = getBotOps(WECHATY_PUPPET, WECHATY_TOKEN) // 获取wechaty配置信息
const bot = WechatyBuilder.build(ops)

await init({
spaceName: process.env['VIKA_SPACE_NAME'],
spaceId: process.env['VIKA_SPACE_ID'],
token: process.env['VIKA_TOKEN'],
}, bot)

// 使用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))
// 初始化检查数据库表,如果不存在则创建
try {
await init({
spaceId: VIKA_SPACE_ID,
token: VIKA_TOKEN,
})
} catch (e) {
logForm('初始化检查失败:' + JSON.stringify(e))
}

bot.use(ChatFlow())
// 启用ChatFlow插件
bot.use(ChatFlow({
spaceId: VIKA_SPACE_ID,
token: VIKA_TOKEN,
adminRoomTopic: ADMINROOM_ADMINROOMTOPIC,
}))

// 启动机器人
bot.start()
.then(() => logForm('1. 机器人启动,如出现二维码,请使用微信扫码登录\n\n2. 如果已经登录成功,则不会显示二维码\n\n3. 如未能成功登录访问 https://www.yuque.com/atorber/chatflow/ibnui5v8mob11d70 查看常见问题解决方法'))
.catch((e: any) => log.error('机器人运行异常:', JSON.stringify(e)))
.catch((e: any) => logForm('机器人运行异常:' + JSON.stringify(e)))
}

void main()
20 changes: 13 additions & 7 deletions example/group-master-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ import {
WechatyBuilder,
} from 'wechaty'

import { getBotOps, log, logForm, GroupMaster, GroupMasterConfig } from '../src/chatflow.js'
import { getBotOps, log, logForm, GroupMaster, GroupMasterConfig } from '../src/index.js'

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
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atorber/chatflow",
"version": "2.0.73",
"version": "3.0.0-Beta-11",
"description": "ChatFlow-聊天机器人管理平台",
"type": "module",
"exports": {
Expand All @@ -21,14 +21,18 @@
"clean": "shx rm -fr dist/*",
"dist": "npm-run-all clean build dist:commonjs",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"init-db": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./example/init-db.ts",
"test-vika-orm": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./tests/vika-orm-test.ts",
"start": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./example/ding-dong-bot.ts",
"start:verbose": "cross-env WECHATY_LOG=verbose NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./example/ding-dong-bot.ts",
"start:gm": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./example/group-master-worker.ts",
"start:index": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./src/index.ts",
"start:notls": "cross-env WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_CLIENT=true WECHATY_PUPPET_SERVICE_AUTHORITY=\"token-service-discovery-test.juzibot.com\" NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./example/ding-dong-bot.ts",
"start:store": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./src/plugins/store-messages-locally.ts",
"start:lark": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./tests/lark.ts",
"start:api": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./tests/api.ts",
"test:lark-api": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./tests/lark.ts",
"test:auth": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./tests/auth.ts",
"test:lark-orm": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./tests/lark-orm-test.ts",
"test:vika-orm": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node ./tests/vika-orm-test.ts",
"rm-temp": "rm -r temp; mkdir temp",
"rm-cache": "rm -r cache; mkdir cache",
"test": "npm run lint",
Expand All @@ -55,7 +59,7 @@
"@vikadata/vika": "^1.0.5",
"@yuque/sdk": "^1.1.1",
"api2d": "^0.1.23",
"axios": "^1.4.0",
"axios": "^1.6.7",
"axios-retry": "^3.8.0",
"boxen": "^7.1.1",
"chatgpt": "^1.4.0",
Expand Down Expand Up @@ -104,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 All @@ -113,10 +118,5 @@
],
"publishConfig": {
"tag": "next"
},
"git": {
"scripts": {
"pre-push": "npx git-scripts-pre-push"
}
}
}
}
Loading