ai_member_xiaokui/memory/2026-04-23.md
--git_token 1dae909219 完善引用回复关系文档:修正技术说明、统一飞书/微信查询示例
- feishu-group-msg-sync/SKILL.md: 修正引用关系识别机制说明(reply_to字段)
- feishu-group-msg-sync/references/query_examples.md: 重写引用查询文档,增加多级追溯、字段对照
- user-feedback-collector/SKILL.md: 新增飞书+微信引用关系统一查询章节
- sync_group_to_mysql.py: 修复extract_quote_message_id从reply_to提取
- sync_feishu_full_history.py: 同步修复
2026-04-23 19:43:37 +08:00

72 lines
3.0 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

# 2026-04-23 工作日志
## 飞书群消息数据库存储方案升级(已完成)
### 背景
李若松要求为飞书群消息记录增加对 link 消息(引用回复)的支持,参考微信反馈数据库的实现逻辑。
### 最终实施方案
**使用现有表 `lark_group_message`**(李若松要求),而非新建表。
1. **数据库表结构升级**
- 为现有 `lark_group_message` 表添加 3 个新字段:
- `parent_id`: 话题父消息 ID
- `root_id`: 话题根消息 ID
- `quote_message_id`: 引用消息 ID核心字段对应微信的 `refer_msg_svrid`
-`quote_message_id` 建立索引支持高效查询
- 执行脚本:`scripts/alter_lark_group_message.sql`
2. **同步脚本更新**
- 更新 `skills/feishu-group-msg-sync/scripts/sync_group_to_mysql.py`
- 从飞书消息 `body.quote` 字段提取引用消息 ID
- 从消息 `parent_id`/`root_id` 提取话题关系
- 媒体文件上传到腾讯 COS
- 支持增量同步(基于上次同步时间)
3. **完整历史数据导入**
- 创建脚本:`scripts/sync_feishu_full_history.py`
- 同步时间范围2026-04-10 至今
- 成功处理 57 条消息(包含文本、图片、视频等多种类型)
- 所有媒体文件已上传到 COS
- 数据已全部写入数据库
4. **定时任务配置**
- 每 4 小时自动同步「内容测试问题反馈」群消息
- crontab: `0 */4 * * * cd /root/.openclaw/workspace-xiaokui/skills/feishu-group-msg-sync/scripts && python3 sync_group_to_mysql.py`
5. **文档更新**
- `feishu-group-msg-sync/SKILL.md`: 说明数据库存储方案和引用回复支持
- `user-feedback-collector/SKILL.md`: 更新飞书反馈数据源为 MySQL
- `feishu-group-msg-sync/references/query_examples.md`: 提供引用回复查询示例
### 技术要点
- **引用回复识别**: 从消息 `body.quote` 字段提取被引用消息的 `message_id`
- **去重机制**: 使用 `UNIQUE KEY (chat_id, message_id)` 避免重复记录
- **数据一致性**: 使用 `ON DUPLICATE KEY UPDATE` 处理重复消息
- **媒体文件处理**: 下载飞书媒体文件并上传到腾讯 COS记录可访问 URL
### 验证结果
- ✅ 数据库表结构已更新3 个新字段)
- ✅ 历史数据已同步57 条消息)
- ✅ 定时任务已配置
- ✅ 文档已更新
- 当前数据中无引用回复消息quote_message_id 都是 NULL说明这段时间内群消息都是直接发送的
### 查询能力
支持以下查询场景:
- 查询某条消息的所有回复
- 查询完整对话链(原消息 + 所有回复)
- 统计热门话题(被回复最多的消息)
- 按时间、发送人、关键词筛选
### 文件清单
- `scripts/alter_lark_group_message.sql` - 数据库表结构升级脚本
- `scripts/sync_feishu_full_history.py` - 完整历史数据同步脚本
- `skills/feishu-group-msg-sync/scripts/sync_group_to_mysql.py` - 增量同步脚本
- `skills/feishu-group-msg-sync/references/query_examples.md` - 查询示例文档