WhatsApp Link
Captures the WhatsApp pairing QR, converts it to a clean PNG on disk, and sends it to the user.
⚠️ The QR expires in ~60 seconds. Only generate it when the user is ready to scan immediately.
⚠️ The script takes ~25–28 seconds to run (WhatsApp-controlled — this cannot be shortened). Tell the user upfront so they're not waiting in silence.
Tell the user: "Have WhatsApp open, go to Settings → Linked Devices → Link a Device. It'll take about 30 seconds to generate — let me know when you're ready." Wait for their confirmation before proceeding.
Steps
1. Fire the script immediately — as your very first action after confirmation:
CODEBLOCK0
⚡ Do not fetch thread context, read other files, or do any other work before starting the script. Every second of delay eats into the 60s QR window. Start the exec first, then do anything else while it runs.
- - The script forks a background process to keep the session alive for ~55s
- It exits immediately once the PNG is written (stdout = file path, stderr = progress)
- Exit code 0 = success; exit code 1 = error (already linked, failed, etc.)
2. Send the file to the user:
CODEBLOCK1
Mattermost thread delivery
If you are in a Mattermost thread (inbound metadata has topic_id or reply_to_id), the message tool cannot post files into threads. Use the Mattermost API directly:
CODEBLOCK2
Replace CHANNEL_ID with the channel from inbound metadata and TOPIC_ID with topic_id (or reply_to_id).
3. Tell the user:
"Scan that QR code in WhatsApp now — it expires in about 60 seconds. Once you've scanned it, WhatsApp will confirm the link. If it expires before you scan, just ask me to generate a new one."
Notes
- -
generate_qr.py handles capture, filtering, and PNG conversion internally - INLINECODE8 is a standalone utility used by
generate_qr.py — no need to call it directly - Use
media: "/tmp/whatsapp_qr.png" to send the file — never pass base64 image data through context - If already linked, the script exits with code 1 and an error message — no QR needed
- Works on any channel (Mattermost, Signal, etc.) —
message tool routes to current conversation - Set COLUMNS=120 is handled internally by the script
- Interactive testing: run the script manually and open the PNG to verify before distributing
Interactive test (console)
CODEBLOCK3
WhatsApp 链接
捕获 WhatsApp 配对二维码,将其转换为清晰的 PNG 文件保存到磁盘,并发送给用户。
⚠️ 二维码约 60 秒后过期。仅在用户准备好立即扫描时生成。
⚠️ 脚本运行需要约 25-28 秒(由 WhatsApp 控制——无法缩短)。请提前告知用户,避免他们无等待。
告知用户:请打开 WhatsApp,进入设置 → 已链接设备 → 链接设备。生成过程大约需要 30 秒——准备好后告诉我。 等待用户确认后再继续。
步骤
1. 立即执行脚本——确认后立即执行的第一步操作:
bash
python3 ./skills/jentic-whatsapp-qr/scripts/generateqr.py /tmp/whatsappqr.png
⚡ 在启动脚本之前,不要获取线程上下文、读取其他文件或执行任何其他工作。 每延迟一秒都会占用 60 秒的二维码窗口期。先执行脚本,然后在脚本运行期间再做其他事情。
- - 脚本会 fork 一个后台进程,将会话保持约 55 秒
- PNG 写入后立即退出(stdout = 文件路径,stderr = 进度)
- 退出码 0 = 成功;退出码 1 = 错误(已链接、失败等)
2. 将文件发送给用户:
python
默认(非 Mattermost,或 Mattermost 主频道):
使用消息工具:
action: send
media: /tmp/whatsapp_qr.png
message: 在 WhatsApp → 设置 → 已链接设备 → 链接设备中扫描此二维码。你大约有 60 秒时间!
Mattermost 线程投递
如果你在 Mattermost 线程 中(入站元数据包含 topicid 或 replyto_id),message 工具无法将文件发布到线程中。请直接使用 Mattermost API:
bash
SHIRKATOKEN=$(python3 -c import json; print(json.load(open(/root/.openclaw/openclaw.json))[env][vars][JENTICMMSHIRKATOKEN]))
1. 上传文件
FILE_ID=$(curl -s -X POST https://mattermost.claw.jentic.ai/api/v4/files \
-H Authorization: Bearer $SHIRKA_TOKEN \
-F channel
id=CHANNELID \
-F files=@/tmp/whatsapp
qr.png;filename=whatsappqr.png \
| python3 -c import json,sys; r=json.load(sys.stdin); print(r[file_infos][0][id]))
2. 发布到线程
curl -s -X POST https://mattermost.claw.jentic.ai/api/v4/posts \
-H Authorization: Bearer $SHIRKA_TOKEN \
-H Content-Type: application/json \
-d {
\channel
id\: \CHANNELID\,
\root
id\: \TOPICID\,
\message\: \立即扫描——你大约有 60 秒时间。WhatsApp → 设置 → 已链接设备 → 链接设备 👇\,
\file
ids\: [\$FILEID\]
}
将 CHANNELID 替换为入站元数据中的频道 ID,将 TOPICID 替换为 topicid(或 replyto_id)。
3. 告知用户:
现在在 WhatsApp 中扫描该二维码——大约 60 秒后过期。扫描后,WhatsApp 会确认链接。如果在扫描前过期,只需让我生成一个新的即可。
备注
- - generateqr.py 内部处理捕获、过滤和 PNG 转换
- qrdecode.py 是 generateqr.py 使用的独立工具——无需直接调用
- 使用 media: /tmp/whatsappqr.png 发送文件——切勿通过上下文传递 base64 图像数据
- 如果已链接,脚本以退出码 1 退出并显示错误信息——无需二维码
- 适用于任何频道(Mattermost、Signal 等)——message 工具会路由到当前对话
- 设置 COLUMNS=120 由脚本内部处理
- 交互式测试: 手动运行脚本并打开 PNG 验证,然后再分发
交互式测试(控制台)
bash
直接运行——stderr 显示进度,成功时 stdout 显示输出路径
python3 skills/jentic-whatsapp-qr/scripts/generate
qr.py /tmp/testqr.png
然后打开/查看 PNG,确认是标准的方形二维码
ls -lh /tmp/test_qr.png