Skip to content

Commit 6e0e5f1

Browse files
author
王允
committed
把信息使用send 发送到微信的 channel中
1 parent e861d86 commit 6e0e5f1

8 files changed

Lines changed: 85 additions & 60 deletions

File tree

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,27 @@ The plugin supports OpenAI-compatible API providers. If not configured in the pl
424424
- After login, messages will be sent to the configured WeChat account
425425

426426
5. **Usage**:
427-
```bash
428-
# Send to WeChat
429-
openclaw gen-cron now daily wechat
427+
**⚠️ Important: WeChat notifications are only supported in OpenClaw chat context, not in CLI mode (`openclaw gen-cron` command)**
428+
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+
```
430435

431-
# Send to multiple channels including WeChat
432-
openclaw gen-cron now daily email,feishu,wechat
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"]}}'
433441
```
434442

435443
**Notes:**
436444
- WeChat notifications are sent as markdown messages to your personal WeChat account
437445
- 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
438448
- If the WeChat plugin is not installed or configured, the plugin will show a warning but continue with other channels
439449

440450
*Required when using this channel

README_CN.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ openclaw plugins install openclaw-github-trending
100100
},
101101
"wechat": {
102102
"enabled": true,
103-
"receiver_id":"your-wechat-user-id@imwechat", // 微信用户 id
103+
"receiver_id": "your-wechat-user-id@imwechat", // 微信用户 id
104104
"bot_account_id": "your-bot-account-id-im-bot" // 微信机器人账号 id
105105
}
106106
},
@@ -427,17 +427,27 @@ openclaw cron rm <job-id>
427427
- 登录后,消息将发送到配置的微信账号
428428

429429
5. **使用方法**
430-
```bash
431-
# 发送到微信
432-
openclaw gen-cron now daily wechat
430+
**⚠️ 重要:微信推送仅支持在 OpenClaw 聊天环境中使用,不支持 CLI 模式(`openclaw gen-cron` 命令)**
431+
432+
**在 OpenClaw 聊天中使用**(推荐):
433+
```text
434+
使用 openclaw-github-trending 工具获取今日热榜并推送到微信
435+
436+
立即执行:获取今日热榜并推送到微信
437+
```
433438

434-
# 同时发送到多个渠道包括微信
435-
openclaw gen-cron now daily email,feishu,wechat
439+
**在聊天中创建定时任务**
440+
```bash
441+
openclaw cron add --name "GitHub 热榜 每日 微信" \
442+
--cron "0 18 * * *" \
443+
--system-event '{"tool":"openclaw-github-trending","params":{"since":"daily","channels":["wechat"]}}'
436444
```
437445

438446
**注意事项:**
439447
- 微信通知以 Markdown 格式发送到您的个人微信账号
440448
- 消息包含新项目(完整 AI 摘要)和持续霸榜项目(简要摘要)
449+
- 微信推送功能依赖 @tencent-weixin/openclaw-weixin 插件提供的 `executeTool` API
450+
- CLI 模式下使用微信通道会返回错误提示
441451
- 如果微信插件未安装或未配置,插件会显示警告但继续向其他渠道推送
442452

443453
*使用该渠道时必填

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.0",
4+
"version": "1.4.1",
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openclaw-github-trending",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
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",
@@ -18,6 +18,7 @@
1818
"trending",
1919
"feishu",
2020
"email",
21+
"wechat",
2122
"ai",
2223
"notifications",
2324
"automation"

src/channels/wechat.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ export class WeChatChannel {
134134
* The plugin should be installed and configured in OpenClaw
135135
*
136136
* @param markdownContent Markdown content to send
137-
* @param openclawApi OpenClaw API instance for invoking tools
137+
* @param openclawApi OpenClaw API instance for invoking channels
138+
* @param config WeChat configuration
138139
* @returns Push result
139140
*/
140141
static async send(
@@ -158,38 +159,37 @@ export class WeChatChannel {
158159
botAccountId: wechatBotAccountId
159160
});
160161

161-
// 使用 OpenClaw system-event 发送微信消息
162-
// 格式参考: {
163-
// "action": "send",
164-
// "channel": "openclaw-weixin",
165-
// "to": "微信 ID(接收者)",
166-
// "accountId": "机器人账号 ID",
167-
// "message": "推送内容"
168-
// }
169-
170-
const systemEventParams = {
171-
action: 'send',
172-
channel: 'openclaw-weixin',
173-
to: wechatReceiverId,
174-
accountId: wechatBotAccountId,
175-
message: markdownContent
176-
};
162+
// 检查 openclawApi 是否包含 channels
163+
if (!openclawApi || !openclawApi.channels) {
164+
logger.error('openclawApi.channels not available');
165+
return {
166+
success: false,
167+
error: 'openclawApi.channels not available - WeChat plugin may not be installed'
168+
};
169+
}
177170

178-
logger.debug('Invoking OpenClaw system-event for WeChat...', {
179-
params: {
180-
action: systemEventParams.action,
181-
channel: systemEventParams.channel,
182-
to: systemEventParams.to,
183-
accountId: systemEventParams.accountId,
184-
message: `${markdownContent.length} chars`
185-
}
171+
// 获取微信 channel 实例
172+
const wechatChannel = openclawApi.channels['openclaw-weixin'];
173+
if (!wechatChannel) {
174+
logger.error('WeChat channel "openclaw-weixin" not found');
175+
return {
176+
success: false,
177+
error: 'WeChat channel "openclaw-weixin" not found - please install and configure the plugin'
178+
};
179+
}
180+
181+
// 直接调用微信 channel 的 send 方法
182+
// OpenClaw 的 channel API 通常有 send 方法
183+
logger.debug('Invoking WeChat channel send...', {
184+
receiverId: wechatReceiverId,
185+
botAccountId: wechatBotAccountId,
186+
messageLength: markdownContent.length
186187
});
187188

188-
// 通过 executeTool 调用 system-event 工具
189-
// OpenClaw 的 system-event 工具用于发送系统级消息到指定通道
190-
const sendResult = await openclawApi.executeTool({
191-
tool_name: 'system-event',
192-
params: systemEventParams
189+
const sendResult = await wechatChannel.send({
190+
to: wechatReceiverId,
191+
accountId: wechatBotAccountId,
192+
message: markdownContent
193193
});
194194

195195
const duration = Date.now() - startTime;

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export default function (api: any) {
4242
channels 推送渠道(多个渠道用逗号分隔)
4343
- email 推送到邮箱
4444
- feishu 推送到飞书
45-
- email,feishu 同时推送到邮箱和飞书
45+
- wechat 推送到微信
46+
- email,feishu,wechat 同时推送到邮箱、飞书和微信
4647
4748
Cron 表达式格式:
4849
格式:分(0-59) 时(0-23) 日(1-31) 月(1-12) 周(0-7, 0和7都是周日)
@@ -63,8 +64,8 @@ Cron 表达式格式:
6364
# 创建定时任务:每月 1 号 9:00 获取本月热榜并推送到邮箱和飞书
6465
openclaw gen-cron "0 9 1 * *" monthly email,feishu
6566
66-
# 创建定时任务:每天早上 8:00 获取今日热榜并推送到邮箱
67-
openclaw gen-cron "0 8 * * *" daily email
67+
# 创建定时任务:每天早上 8:00 获取今日热榜并推送到邮箱和微信
68+
openclaw gen-cron "0 8 * * *" daily email,wechat
6869
6970
提示:
7071
- 推送渠道需要在 ~/.openclaw/openclaw.json 中配置

src/tool.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -387,19 +387,25 @@ async function githubTrendingHandler(
387387
continue;
388388
}
389389

390-
console.log('[WeChat Channel] Sending to WeChat via openclaw-weixin plugin...');
390+
// WeChat channel requires OpenClaw runtime context with channels available
391+
// The openclaw-weixin plugin should be installed and configured
392+
const channels = (openclawConfig as any).channels || (openclawConfig as any).api?.channels;
393+
394+
if (!channels) {
395+
pushResults.push({
396+
channel: 'wechat',
397+
success: false,
398+
error: 'channels not available - WeChat plugin may not be installed'
399+
});
400+
pushLogs.push('[WeChat Channel] ❌ 推送失败: WeChat plugin not available');
401+
continue;
402+
}
391403

392404
// Build markdown content
393405
const markdownContent = WeChatChannel.buildMarkdown(processedRepositories, seenReposWithSummary, since);
394406

395-
console.log(`[WeChat Channel] Markdown content length: ${markdownContent.length} chars`);
396-
397-
// Try to send via WeChat plugin tool
398-
const result = await WeChatChannel.send(markdownContent, { executeTool: async (params: any) => {
399-
// This is a placeholder - the actual executeTool will be provided by OpenClaw at runtime
400-
console.error('[WeChat Channel] executeTool not available in tool.ts');
401-
throw new Error('executeTool not available');
402-
} }, pluginConfig?.channels?.wechat || {});
407+
// Send via WeChat channel using direct channel API
408+
const result = await WeChatChannel.send(markdownContent, { channels }, wechatConfig || {});
403409

404410
pushResults.push({
405411
channel: 'wechat',
@@ -408,9 +414,6 @@ async function githubTrendingHandler(
408414
error: result.error
409415
});
410416
pushLogs.push(`[WeChat Channel] ${result.success ? '✅ 推送成功' : '❌ 推送失败'}${result.error ? ': ' + result.error : ''}`);
411-
if (!result.success) {
412-
pushLogs.push('[WeChat Channel] ⚠️ 可能是因为 @tencent-weixin/openclaw-weixin 插件未安装或未配置');
413-
}
414417
}
415418
} catch (error) {
416419
pushResults.push({

0 commit comments

Comments
 (0)