Files
2026-12-04 09:44:59 +08:00

128 lines
3.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# record-bot
微信记录助手:接收 `weixin-ilink-gateway` 推送的消息,按规则归类并写入 SQLite,可选回执到微信;带 Vue 管理页。
技术栈:**.NET 8** / ASP.NET Core Minimal API / EF Core SQLite / **Vue 3 + Vite**。
## 架构
```text
微信 → weixin-ilink-gateway ──WEBHOOK──► record-bot
├─ 关键词归类
├─ 图片经 gateway 解密下载
├─ SQLite 落库
└─ POST /messages/send 回执
浏览器 ──► Vue 管理页 ──► /records · /records/stats
```
## 快速开始
### 1. 配置
编辑 `src/RecordBot/appsettings.Development.json`(或环境变量):
| 配置 | 说明 |
| --- | --- |
| `Gateway:BaseUrl` | gateway 地址,本地默认 `http://127.0.0.1:3456` |
| `Gateway:ApiKey` | 与 gateway 的 `API_KEY` 相同 |
| `RecordBot:WebhookToken` | 可选;设置后要求 `X-Record-Token` 或 `?token=` |
| `RecordBot:AllowedUserIds` | 可选白名单;空数组表示接受所有人 |
| `RecordBot:ReplyOnRecord` | 记录成功后是否微信回执 |
### 2. 构建前端并运行 API
```bash
cd web
npm install
npm run build # 输出到 src/RecordBot/wwwroot
cd ../src/RecordBot
dotnet run
```
打开:`http://localhost:5000/`
### 3. 前端开发模式(热更新)
先启动 record-bot(5000),再:
```bash
cd web
npm run dev
```
打开 Vite:`http://localhost:5173/`(已代理 `/api` → `http://127.0.0.1:5000`)。
### 4. 配置 gateway Webhook
在 `weixin-ilink-gateway` 的 `.env` 中:
```env
WEBHOOK_URLS=http://127.0.0.1:5000/webhook/weixin
```
然后扫码登录 gateway,用手机给 Bot 发消息即可。
### Docker / 1Panel(Rocky Linux)
仓库根目录有完整编排(gateway + record-bot,镜像内会编 Vue 管理页):
```bash
cd WeChatBot # 仓库根
cp .env.example .env # 填写 GATEWAY_API_KEY、LLM_API_KEY
docker compose up -d --build
```
- 管理页:`http://服务器:5080/`
- Gateway:`http://服务器:29527/`(扫码登录按 gateway 文档)
- 数据:`./data/gateway`、`./data/record-bot`(可改 `.env` 里路径)
仅部署 record-bot:`cd record-bot && docker compose up -d --build`(需自备 gateway,并设 `GATEWAY_BASE_URL`)。
无 Docker 时可用 `src/RecordBot/publish-linux.bat` 打 `linux-x64` 自包含包。
## 用法(微信里发)
| 你发的内容 | 效果 |
| --- | --- |
| `提醒我明天8点50打卡` | 到点微信推送「打卡」 |
| `明天六点四十提醒我起床` | 支持中文数字时间 |
| `每天早上八点五十提醒我打卡` | 每天重复提醒 |
| `我的提醒` / `取消提醒 3` | 查看 / 取消定时提醒 |
| `#支出 午餐 35` | 归入「支出」,金额 35 |
| `支出:买菜 42.5` | 同上 |
| `待办 明天交房租` | 归入「待办」 |
| 纯文字 | 默认「笔记」 |
| 图片 | 默认「照片」,并下载到 `data/media` |
| `帮助` / `查询` / `统计` | 命令:说明 / 最近记录 / 本月收支 |
分类关键词可在 `appsettings.json` → `RecordBot:Categories` 修改。
## HTTP API
| 方法 | 路径 | 说明 |
| --- | --- | --- |
| POST | `/webhook/weixin` | 供 gateway 推送(原始 WeixinMessage JSON) |
| GET | `/records?userId=&category=&take=50` | 查询记录 |
| GET | `/records/stats?userId=` | 本月统计 |
| GET | `/health` | 健康检查 |
开发环境可打开 Swagger:`http://localhost:5000/swagger`。
## 目录
```text
record-bot/
├── docker-compose.yaml
├── README.md
├── web/ # Vue 3 管理端
└── src/RecordBot/
├── Program.cs
├── wwwroot/ # npm run build 产出
├── Data/
├── Models/
├── Options/
└── Services/
```