Skip to content

Commit 38891e9

Browse files
author
王允
committed
消息同步到微信中
1 parent 5acf8a6 commit 38891e9

9 files changed

Lines changed: 356 additions & 82 deletions

File tree

README.md

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -375,36 +375,55 @@ The plugin supports OpenAI-compatible API providers. If not configured in the pl
375375

376376
| Field | Type | Required | Default | Description |
377377
|-------|------|----------|---------|-------------|
378-
| `enabled` | boolean | No | `false` | Enable WeChat notifications via @tencent-weixin/openclaw-weixin plugin |
379-
| `receiver_id` | string | No | - | WeChat receiver ID (format: `xxx@im.wechat`) |
378+
| `enabled` | boolean | No | `true` | Enable WeChat notifications via @tencent-weixin/openclaw-weixin plugin |
379+
| `receiver_id` | string | No | Auto-detect | WeChat receiver ID (format: `xxx@im.wechat`) |
380380
| `bot_account_id` | string | No | - | WeChat bot account ID (format: `xxx-im-bot`) |
381381

382+
**receiver_id Auto-Detection:**
383+
384+
The plugin will automatically detect `receiver_id` using the following priority (no manual configuration needed in most cases):
385+
386+
1. **Plugin Config**: `plugins.openclaw-github-trending.config.channels.wechat.receiver_id`
387+
2. **Environment Variable**: `OPENCLAW_WECHAT_RECEIVER_ID`
388+
3. **Message Context**: If current session is from WeChat, auto-reply to sender
389+
4. **Session History**: Extract from `~/.openclaw/agents/main/sessions/sessions.json`
390+
5. **OpenClaw Config**: Search WeChat plugin configuration and sessions
391+
392+
**⚠️ Important:**
393+
- WeChat ID is **case-sensitive**, e.g., `o9cq806Il_QmHA022BUNXe0hUv4I@im.wechat`
394+
- If auto-detection fails, detailed configuration guide will be shown
395+
382396
**WeChat Requirements:**
383397

384398
1. **Install WeChat Plugin**:
385399
```bash
386-
npm install @tencent-weixin/openclaw-weixin
400+
openclaw plugins install @tencent-weixin/openclaw-weixin
387401
```
388402

389403
2. **Configure in OpenClaw** (`~/.openclaw/openclaw.json`):
390404
```json
391405
{
392406
"plugins": {
393407
"entries": {
394-
"@tencent-weixin/openclaw-weixin": {
395-
"enabled": true,
396-
"config": {
397-
"enable_login": true
398-
}
399-
},
408+
"openclaw-weixin": {
409+
"enabled": true
410+
}
411+
}
412+
}
413+
}
414+
```
415+
416+
3. **Optional: Configure receiver_id** (only if you need to push to a specific user):
417+
```json
418+
{
419+
"plugins": {
420+
"entries": {
400421
"openclaw-github-trending": {
401-
"enabled": true,
402422
"config": {
403423
"channels": {
404424
"wechat": {
405425
"enabled": true,
406-
"receiver_id": "xxx@im.wechat",
407-
"bot_account_id": "xxx-im-bot"
426+
"receiver_id": "o9cq806Il_QmHA022BUNXe0hUv4I@im.wechat"
408427
}
409428
}
410429
}
@@ -414,38 +433,24 @@ The plugin supports OpenAI-compatible API providers. If not configured in the pl
414433
}
415434
```
416435

417-
3. **Configuration Options (choose one)**:
418-
- **Config File (Recommended)**: Set `receiver_id` and `bot_account_id` in the `wechat` section of `openclaw.json`
419-
- **Environment Variables**: Set `OPENCLAW_WECHAT_RECEIVER_ID` and `OPENCLAW_WECHAT_BOT_ACCOUNT_ID`
420-
- **Default Values**: Use built-in default configuration (for testing only)
436+
**💡 Tip**: If `receiver_id` is not configured, the plugin will auto-detect it from session history.
421437

422-
4. **Login to WeChat**:
423-
- OpenClaw will prompt you to scan QR code with your personal WeChat
424-
- After login, messages will be sent to the configured WeChat account
438+
**🔍 How to Get Your WeChat ID:**
425439

426-
5. **Usage**:
427-
**⚠️ Important: WeChat notifications are only supported in OpenClaw chat context, not in CLI mode (`openclaw gen-cron` command)**
440+
```bash
441+
# Method 1: Check OpenClaw session history
442+
cat ~/.openclaw/agents/main/sessions/sessions.json | jq 'to_entries[] | select(.key | contains("wechat")) | {key, lastTo}'
428443

429-
**Use in OpenClaw Chat** (Recommended):
430-
```text
431-
Use openclaw-github-trending tool to get today's trending and push to WeChat
432-
or
433-
Run immediately: Fetch today's trending and push to WeChat
434-
```
444+
# Method 2: Check message send records
445+
cat ~/.openclaw/agents/main/sessions/sessions.json | grep -i "o9cq.*@im.wechat"
435446

436-
**Create scheduled task in chat**:
437-
```bash
438-
openclaw cron add --name "GitHub Trending Daily WeChat" \
439-
--cron "0 18 * * *" \
440-
--system-event '{"tool":"openclaw-github-trending","params":{"since":"daily","channels":["wechat"]}}'
441-
```
447+
# Method 3: Send a test message and check logs
448+
openclaw message send --channel openclaw-weixin --target "your-wechat-id" "test"
449+
```
442450

443-
**Notes:**
444-
- WeChat notifications are sent as markdown messages to your personal WeChat account
445-
- Messages include new repositories (with full AI summaries) and trending repositories (with brief summaries)
446-
- WeChat functionality depends on the `executeTool` API provided by @tencent-weixin/openclaw-weixin plugin
447-
- CLI mode will return an error when using WeChat channel
448-
- If the WeChat plugin is not installed or configured, the plugin will show a warning but continue with other channels
451+
**⚠️ Notes:**
452+
- WeChat ID format: `o9cq806Il_QmHA022BUNXe0hUv4I@im.wechat` (case-sensitive!)
453+
- If auto-detection fails, error message includes detailed configuration guide
449454

450455
*Required when using this channel
451456

README_CN.md

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ openclaw plugins install openclaw-github-trending
100100
},
101101
"wechat": {
102102
"enabled": true,
103-
"receiver_id": "your-wechat-user-id@imwechat", // 微信用户 id
104-
"bot_account_id": "your-bot-account-id-im-bot" // 微信机器人账号 id
103+
"receiver_id": "your-wechat-user-id@im.wechat", // 可选:微信用户 ID,不配置会尝试自动获取
104+
"bot_account_id": "your-bot-account-id-im-bot" // 可选:微信机器人账号 ID
105105
}
106106
},
107107
// 可选:开启历史记录功能,用于智能去重
@@ -378,25 +378,83 @@ openclaw cron rm <job-id>
378378

379379
| 字段 | 类型 | 必填 | 默认值 | 说明 |
380380
|-------|------|----------|---------|-------------|
381-
| `enabled` | boolean || `false` | 通过 @tencent-weixin/openclaw-weixin 插件启用微信通知 |
382-
| `receiver_id` | string || - | 微信接收者 ID(格式:`xxx@im.wechat`|
381+
| `enabled` | boolean || `true` | 通过 @tencent-weixin/openclaw-weixin 插件启用微信通知 |
382+
| `receiver_id` | string || 自动获取 | 微信接收者 ID(格式:`xxx@im.wechat`|
383383
| `bot_account_id` | string || - | 微信机器人账号 ID(格式:`xxx-im-bot`|
384384

385+
**receiver_id 自动获取机制:**
386+
387+
插件会按以下优先级自动获取 `receiver_id`**通常无需手动配置**
388+
389+
1. **插件配置**`plugins.openclaw-github-trending.config.channels.wechat.receiver_id`
390+
2. **环境变量**`OPENCLAW_WECHAT_RECEIVER_ID`
391+
3. **消息上下文**:如果当前会话来自微信,自动回复给发送者
392+
4. **会话历史**:从 `~/.openclaw/agents/main/sessions/sessions.json` 中提取最近使用的微信 ID
393+
5. **OpenClaw 配置**:从微信插件的配置和会话中查找
394+
395+
**⚠️ 重要提示:**
396+
- 微信 ID **区分大小写**,例如:`o9cq806Il_QmHA022BUNXe0hUv4I@im.wechat`
397+
- 如果自动获取失败,会显示详细的配置指南和获取方法
398+
385399
**微信推送配置要求:**
386400

387401
1. **安装微信插件**
388402
```bash
389-
npm install @tencent-weixin/openclaw-weixin
403+
openclaw plugins install @tencent-weixin/openclaw-weixin
390404
```
391405

392406
2. **在 OpenClaw 中配置** (`~/.openclaw/openclaw.json`):
393407
```json
394408
{
395409
"plugins": {
396410
"entries": {
397-
"@tencent-weixin/openclaw-weixin": {
398-
"enabled": true,
411+
"openclaw-weixin": {
412+
"enabled": true
413+
}
414+
}
415+
}
416+
}
417+
```
418+
419+
3. **可选:配置 receiver_id**(仅在需要推送到特定用户时):
420+
```json
421+
{
422+
"plugins": {
423+
"entries": {
424+
"openclaw-github-trending": {
399425
"config": {
426+
"channels": {
427+
"wechat": {
428+
"enabled": true,
429+
"receiver_id": "xxx@im.wechat"
430+
}
431+
}
432+
}
433+
}
434+
}
435+
}
436+
}
437+
```
438+
439+
**💡 提示**:如果不配置 `receiver_id`,插件会自动从会话历史中获取。
440+
441+
**🔍 如何获取你的微信 ID:**
442+
443+
```bash
444+
# 方法 1:查看 OpenClaw 会话历史
445+
cat ~/.openclaw/agents/main/sessions/sessions.json | jq 'to_entries[] | select(.key | contains("wechat")) | {key, lastTo}'
446+
447+
# 方法 2:查看消息发送记录
448+
cat ~/.openclaw/agents/main/sessions/sessions.json | grep -i "o9cq.*@im.wechat"
449+
450+
# 方法 3:发送一次测试消息后查看日志
451+
openclaw message send --channel openclaw-weixin --target "你的微信 ID" "测试"
452+
```
453+
454+
**⚠️ 注意事项:**
455+
- 微信 ID 格式:`o9cq806Il_QmHA022BUNXe0hUv4I@im.wechat`(区分大小写!)
456+
- 如果自动获取失败,错误信息会包含详细的配置指南
457+
400458
"enable_login": true
401459
}
402460
},

openclaw.plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "openclaw-github-trending",
33
"name": "GitHub Trending",
4-
"version": "1.4.2",
4+
"version": "1.4.3",
55
"description": "Fetch GitHub trending repositories and push to Feishu or Email with AI summaries",
66
"author": "王允",
77
"license": "MIT",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openclaw-github-trending",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"description": "OpenClaw plugin for fetching GitHub trending repositories and pushing to Feishu or Email with AI summaries",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)