ClawSkills logoClawSkills

Google Messages

通过 Google Messages 网页界面发送和接收 SMS/RCS。当被要求“发送短信”、“查看短信”、“SMS”、“text message”、“Google

介绍

# Google Messages Browser Skill

使用 `browser` 工具通过 messages.google.com 自动化 SMS/RCS 消息发送。

## 概述

Google Messages 网页版允许您通过浏览器从 Android 手机发送/接收文本消息。此技能实现了该接口的自动化。

**要求:** - 安装了 Google Messages 应用的 Android 手机 - 手机和电脑在同一网络(用于初始二维码配对) - 具有持久会话的浏览器配置文件(使用 `openclaw` 或您首选的配置文件)

**注意:** 如果不同,请将示例中的 `profile=openclaw` 替换为您首选的浏览器配置文件。

---

## 快速参考

| 操作 | 命令 | |--------|---------| | 打开配对页面 | `browser action=open profile=openclaw targetUrl="https://messages.google.com/web/authentication"` | | 检查会话 | `browser action=snapshot profile=openclaw` — 查找对话列表与二维码的对比 | | 截取屏幕截图 | `browser action=screenshot profile=openclaw` |

---

## 初始设置(二维码配对)

首次设置需要扫描二维码:

1. **打开 Google Messages 网页版** ``` browser action=open profile=openclaw targetUrl="https://messages.google.com/web/authentication" ```

2. **截取二维码的屏幕截图**并分享给用户 ``` browser action=screenshot profile=openclaw ```

3. **用户使用手机扫描:** - 在 Android 上打开 Google Messages 应用 - 点击 ⋮ 菜单 → "设备配对" (Device pairing) → "二维码扫描器" (QR code scanner) - 扫描二维码

4. **验证连接** — 快照应显示对话列表,而不是二维码

**重要提示:** 启用“记住此电脑”以保持会话持久化。

---

## 发送消息

1. **导航到对话** ``` browser action=navigate profile=openclaw targetUrl="https://messages.google.com/web/conversations" ```

2. **拍摄快照并查找对话** ``` browser action=snapshot profile=openclaw ``` 在对话列表中查找联系人,记下 `ref`。

3. **点击对话** ``` browser action=act profile=openclaw request={"kind": "click", "ref": "<ref>"} ```

4. **输入消息**(从快照中查找 textarea ref) ``` browser action=act profile=openclaw request={"kind": "type", "ref": "<input_ref>", "text": "Your message"} ```

5. **点击发送**(查找发送按钮 ref) ``` browser action=act profile=openclaw request={"kind": "click", "ref": "<send_ref>"} ```

---

## 接收消息(实时通知)

此技能包含一个用于实时接收 SMS 通知的 webhook 系统。

### 组件

1. **sms-webhook-server.js** — 接收通知,转发到 OpenClaw 通道 2. **sms-observer.js** — 监视新消息的浏览器脚本

### 设置

1. **设置环境变量:** ```bash export SMS_NOTIFICATION_TARGET="telegram:YOUR_CHAT_ID" export SMS_NOTIFICATION_CHANNEL="telegram" ```

2. **启动 webhook 服务器:** ```bash node <skill>/sms-webhook-server.js ```

3. **将观察器注入浏览器**(参见 `references/observer-injection.md`)

### Systemd 服务(持久化)

```bash cp <skill>/systemd/google-messages-webhook.service ~/.config/systemd/user/ # Edit service file: set SMS_NOTIFICATION_TARGET in Environment= systemctl --user daemon-reload systemctl --user enable --now google-messages-webhook ```

---

## 读取消息

请参阅 `references/snippets.md` 以获取 JavaScript 代码片段,用于: - 获取最近的对话 - 获取当前对话中的消息 - 检查会话状态

---

## 故障排除

| 问题 | 解决方案 | |---------|----------| | 显示二维码 | 会话已过期,请重新配对 | | 未找到元素 | Google 更新了 UI,请检查快照以获取新的选择器 | | 发送按钮被禁用 | 消息输入为空或手机已断开连接 | | 观察器未检测到 | 检查浏览器控制台是否有 `[SMS Observer]` 日志 | | Webhook 未收到 | 验证服务器是否正在运行:`curl http://127.0.0.1:19888/health` |

---

## 选择器参考

Google Messages 使用 Angular 组件。这些可能会随更新而更改。

| 元素 | 选择器 | |---------|----------| | 对话列表 | `mws-conversations-list` | | 对话项 | `mws-conversation-list-item` | | 消息输入框 | `textarea[aria-label*="message"]` | | 发送按钮 | `button[aria-label*="Send"]` | | 二维码 | `mw-qr-code` |

---

## 限制

- 手机必须在线(消息通过手机同步) - 浏览器标签页必须保持打开才能接收通知 - 会话在大约 14 天不活动后过期 - 页面重新加载后观察器会丢失(需要重新注入)

---

## 安全性

- Webhook 仅监听本地主机 (127.0.0.1) - 不存储凭据(会话在浏览器 cookies 中) - 二维码配对链接到您的手机 — 请视为敏感信息

---

## 许可证

Apache-2.0

更多产品