将本地命令行工具桥接到微信 —— 通过 OpeniLink Hub 接收微信命令,在本地执行,返回结果。
微信用户 → /weather 北京 → Hub → WebSocket → Runner → curl wttr.in/北京 → 结果返回微信
- 在 YAML 配置中定义命令(名称 + shell 命令)
- Runner 启动时自动同步命令到 Hub
- 通过 WebSocket 保持连接,接收来自微信的命令事件
- 在本地执行对应 shell 命令,将输出返回给微信用户
npm install -g openilink-app-runneropenilink-app-runner init --hub-url https://hub.openilink.com --token app_xxx配置文件保存在标准目录:
- macOS:
~/Library/Application Support/openilink-app-runner/runner.yaml - Linux:
~/.config/openilink-app-runner/runner.yaml - root:
/etc/openilink-app-runner/runner.yaml
# 添加查天气命令(单引号包裹,${args} 不会被 shell 展开)
openilink-app-runner add weather 'curl -s "wttr.in/${args}?format=3"' -d "查天气" -t 5
# 添加查 IP 命令(无参数,不涉及 ${args})
openilink-app-runner add ip "curl -s ifconfig.me" -d "查公网 IP" -t 5
# 查看已添加的命令
openilink-app-runner list添加命令时会自动同步到 Hub。
openilink-app-runner start现在在微信中发送 /weather 北京 即可看到天气结果。
所有命令支持 -c, --config <path> 指定自定义配置文件路径。
hub_url: "https://hub.openilink.com"
app_token: "app_your_token_here"
max_output: 2000 # 输出最大字符数
commands:
weather:
description: "查天气"
exec: "curl -s 'wttr.in/${args}?format=3'"
timeout: 5 # 秒,默认 30
ip:
description: "查公网 IP"
exec: "curl -s ifconfig.me"
timeout: 5hub_url— Hub 服务地址(必填)app_token— App Token,在 Hub 中创建 App 后获取(必填)max_output— 命令输出最大字符数,超出截断(默认 2000)commands— 命令映射description— 命令描述,会显示在微信中exec— 要执行的 shell 命令,支持${args}占位符接收用户输入timeout— 超时秒数(默认 30)
${args} 会直接替换到 shell 命令中,存在命令注入风险。请注意:
- 仅在信任的微信群/用户中使用
- 避免在
exec中使用${args}执行危险操作(如rm、sudo等) - 设置合理的
timeout防止命令卡住 max_output限制输出大小,防止刷屏
commands:
hn:
description: "HackerNews 热门"
exec: "opencli hackernews top --format json"
timeout: 10
github:
description: "GitHub 趋势"
exec: "opencli github trending ${args}"
timeout: 10Runner 会自动维护 WebSocket 连接。断开后每 5 秒自动重连,同时通过 ping/pong 保持心跳。
openilink-app-runner bridges local CLI commands to WeChat via OpeniLink Hub. Define commands in a YAML config, and WeChat users can invoke them by sending /command args.
- Define commands in
runner.yaml(name + shell command) - Runner syncs commands to Hub on startup
- Stays connected via WebSocket, receives command events from WeChat
- Executes shell commands locally, returns output to WeChat
npm install -g openilink-app-runner
openilink-app-runner init --hub-url https://hub.openilink.com --token app_xxx
openilink-app-runner add weather 'curl -s "wttr.in/${args}?format=3"' -d "Weather" -t 5
openilink-app-runner start${args} is interpolated directly into shell commands. Only use in trusted environments. Set reasonable timeouts and output limits.
MIT
