This commit is contained in:
mayunfei committed 2026-12-04 09:44:59 +08:00
commit 5f8428a318
1688 files changed
+39031

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
**/bin/
**/obj/
**/node_modules/
**/publish/
**/publish-linux/
**/data/
**/storage/
**/.git/
**/.vs/
**/*.user
**/appsettings.local.json
**/appsettings.*.local.json
web/dist/
*.md
*.zip
+16
View File
@@ -0,0 +1,16 @@
bin/
obj/
data/
storage/
*.user
*.db
*.db-shm
*.db-wal
.vs/
.idea/
appsettings.local.json
appsettings.*.local.json
.env
web/node_modules/
web/dist/
src/RecordBot/wwwroot/
+34
View File
@@ -0,0 +1,34 @@
# Build context: record-bot/ (repo folder that contains web/ and src/)
# Multi-stage: Vue admin → .NET publish → slim runtime
FROM node:22-alpine AS web
WORKDIR /web
COPY web/package.json web/package-lock.json ./
RUN npm ci
COPY web/ ./
# Override vite outDir so Docker layout does not depend on ../src/RecordBot/wwwroot
RUN npx vue-tsc -b && npx vite build --outDir /wwwroot --emptyOutDir
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY src/RecordBot/RecordBot.csproj .
RUN dotnet restore
COPY src/RecordBot/ .
COPY --from=web /wwwroot ./wwwroot
RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
RUN mkdir -p /app/data/media /app/data/backups \
&& ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo Asia/Shanghai > /etc/timezone
ENV ASPNETCORE_URLS=http://+:8080 \
TZ=Asia/Shanghai \
RecordBot__ConnectionString="Data Source=/app/data/records.db" \
RecordBot__MediaDir=/app/data/media \
RecordBot__BackupDir=/app/data/backups \
RecordBot__TimeZoneId=Asia/Shanghai
EXPOSE 8080
COPY --from=build /app/publish .
VOLUME ["/app/data"]
ENTRYPOINT ["dotnet", "RecordBot.dll"]
+127
View File
@@ -0,0 +1,127 @@
# 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/
```
+8
View File
@@ -0,0 +1,8 @@
<Solution>
<Folder Name="/src/">
<Project Path="src/RecordBot/RecordBot.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/RecordBot.Tests/RecordBot.Tests.csproj" />
</Folder>
</Solution>
+31
View File
@@ -0,0 +1,31 @@
# 本地带源码构建用。生产无源码、分开部署:见 ../deploy/record-bot.compose.yaml
services:
record-bot:
image: ${RECORD_BOT_IMAGE:-record-bot:local}
build:
context: .
dockerfile: Dockerfile
container_name: record-bot
ports:
- "${RECORD_BOT_PORT:-5080}:8080"
environment:
ASPNETCORE_ENVIRONMENT: Production
TZ: Asia/Shanghai
Gateway__BaseUrl: ${GATEWAY_BASE_URL:-http://host.docker.internal:29527}
Gateway__ApiKey: ${GATEWAY_API_KEY:?set GATEWAY_API_KEY}
RecordBot__WebhookToken: ${RECORD_WEBHOOK_TOKEN:-}
RecordBot__ReplyOnRecord: "true"
RecordBot__ConnectionString: "Data Source=/app/data/records.db"
RecordBot__MediaDir: /app/data/media
RecordBot__BackupDir: /app/data/backups
RecordBot__TimeZoneId: Asia/Shanghai
Llm__Enabled: ${LLM_ENABLED:-true}
Llm__ApiKey: ${LLM_API_KEY:-}
Llm__BaseUrl: ${LLM_BASE_URL:-https://dashscope.aliyuncs.com/compatible-mode/v1}
Llm__Model: ${LLM_MODEL:-qwen3.8-max}
volumes:
- ${RECORD_DATA_DIR:-./data}:/app/data
extra_hosts:
- "host.docker.internal:host-gateway"
restart: unless-stopped
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loaded 100 of 1688 files, more files were not shown because too many files have changed in this diff. Show more