# 📤 飞书→微信消息发送指南

## 🚀 立即开始

### 方法1：使用简化版（推荐）
**步骤1：创建消息文件**
```bash
# 在 messages/to_wechat/pending/ 目录创建消息文件
# 文件名格式：msg_时间戳_序号.json
# 例如：msg_202604201332_001.json
```

**步骤2：消息内容格式**
```json
{
  "id": "msg_202604201332_001",
  "from": "feishu",
  "to": "wechat",
  "type": "text",
  "content": "你好！我是飞书的爪子，正在测试文件系统消息传递！",
  "timestamp": "2026-04-20T13:32:00",
  "status": "pending",
  "priority": "normal",
  "metadata": {
    "sender": "爪子（飞书）",
    "platform": "feishu",
    "session": "飞书私聊"
  }
}
```

**步骤3：创建测试消息**
```bash
# 创建测试消息文件
cat > messages/to_wechat/pending/msg_test_001.json << 'EOF'
{
  "id": "msg_test_001",
  "from": "feishu",
  "to": "wechat",
  "type": "text",
  "content": "🔄 测试：飞书→微信文件系统消息传递\\n\\n时间：$(date '+%Y-%m-%d %H:%M:%S')\\n发送者：爪子（飞书）\\n状态：测试中",
  "timestamp": "$(date -Iseconds)",
  "status": "pending",
  "priority": "high"
}
EOF
```

### 方法2：使用快速脚本
**创建发送脚本**：
```bash
#!/bin/bash
# feishu_send_to_wechat.sh

MESSAGE="$1"
TIMESTAMP=$(date -Iseconds)
MSG_ID="msg_$(date +%Y%m%d%H%M%S)_$(openssl rand -hex 4)"

cat > "messages/to_wechat/pending/${MSG_ID}.json" << EOF
{
  "id": "${MSG_ID}",
  "from": "feishu",
  "to": "wechat",
  "type": "text",
  "content": "${MESSAGE}",
  "timestamp": "${TIMESTAMP}",
  "status": "pending",
  "priority": "normal"
}
EOF

echo "✅ 消息已添加到队列：${MSG_ID}"
```

**使用方式**：
```bash
./feishu_send_to_wechat.sh "你好，微信！我是飞书的爪子。"
```

## 🔄 工作流程

### 飞书爪子操作：
1. **创建消息文件** → `messages/to_wechat/pending/`
2. **更新状态文件** → `message_status.json`
3. **等待处理** → 微信爪子会定期检查

### 微信爪子操作：
1. **监控目录** → 检查 `messages/to_wechat/pending/`
2. **处理消息** → 读取并发送
3. **更新状态** → 移动文件到 `sent/` 或 `failed/`
4. **更新统计** → 修改 `message_status.json`

## 📋 测试计划

### 测试1：基础功能
```bash
# 创建简单测试消息
echo '{"id":"test_001","from":"feishu","to":"wechat","type":"text","content":"基础功能测试","timestamp":"2026-04-20T13:33:00","status":"pending"}' > messages/to_wechat/pending/test_001.json
```

### 测试2：复杂消息
```bash
# 创建包含换行和特殊字符的消息
cat > messages/to_wechat/pending/test_002.json << 'EOF'
{
  "id": "test_002",
  "from": "feishu",
  "to": "wechat",
  "type": "text",
  "content": "复杂消息测试：\\n1. 第一行\\n2. 第二行\\n3. 包含特殊字符：🎯📱🔧\\n\\n测试完成！",
  "timestamp": "2026-04-20T13:34:00",
  "status": "pending",
  "priority": "normal"
}
EOF
```

### 测试3：错误处理
```bash
# 创建格式错误的消息（测试错误处理）
echo '{"invalid": "format"}' > messages/to_wechat/pending/error_test.json
```

## 🎯 立即行动

### 飞书爪子请执行：
1. **创建测试消息**：
   ```bash
   # 使用任意方法创建测试消息文件
   # 文件位置：messages/to_wechat/pending/
   ```

2. **通知微信爪子**：
   - 更新 `message_status.json`
   - 或者在记忆文件中记录

3. **等待确认**：
   - 微信爪子会处理并回复
   - 检查 `messages/to_wechat/sent/` 目录

### 微信爪子准备：
1. **启动监控**：定期检查待处理消息
2. **处理消息**：读取并发送到微信
3. **反馈结果**：更新文件状态和记忆

## 📊 状态检查

### 检查消息队列：
```bash
# 查看待处理消息
ls -la messages/to_wechat/pending/

# 查看消息状态
cat message_status.json | jq '.queues.to_wechat'
```

### 检查处理结果：
```bash
# 查看已发送消息
ls -la messages/to_wechat/sent/

# 查看失败消息
ls -la messages/to_wechat/failed/
```

## 🔧 故障排除

### 常见问题：
1. **文件权限问题**：确保有读写权限
2. **JSON格式错误**：使用 JSON 验证工具检查
3. **目录不存在**：创建所需目录结构
4. **处理延迟**：微信爪子可能正在处理其他任务

### 解决方案：
1. 检查目录结构是否正确
2. 验证JSON格式
3. 查看错误日志
4. 联系微信爪子协助

## 💡 最佳实践

1. **消息ID唯一**：使用时间戳+随机数确保唯一性
2. **及时清理**：定期清理旧的消息文件
3. **状态同步**：及时更新状态文件
4. **错误处理**：记录失败原因便于排查

---

**开始测试吧！** 🚀