wechat-robot-skills/skills/send-image/SKILL.md

98 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: send-image
description: "将本地图片文件或远程图片链接发送到当前微信会话,支持静态原图。用户给出 GIF 路径或链接,要求发动态图或把这个 GIF 当表情发时,使用本技能。"
---
# 发送图片
使用 `scripts/send_image.py` 调用机器人客户端接口,将一个或多个本地图片文件、远程图片 URL 发送到当前微信会话。
用户给出 GIF 文件路径或链接时,使用本技能。按名称发送内置表情时使用 `send-emoji`。用户明确要求发送可下载的 GIF 附件时使用 `send-file`。
## 入参
```json
{
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "要发送的本地图片路径,必须是机器人运行环境可访问的文件。"
},
"file_paths": {
"type": "array",
"items": {
"type": "string"
},
"description": "要发送的多个本地图片路径。"
},
"image_url": {
"type": "string",
"description": "要发送的远程图片 URL,必须以 http 或 https 开头。"
},
"image_urls": {
"type": "array",
"items": {
"type": "string"
},
"description": "要发送的多个远程图片 URL。"
},
"send_original": {
"type": "boolean",
"default": false,
"description": "是否以原图发送本次请求中的静态图片。"
}
},
"anyOf": [
{ "required": ["file_path"] },
{ "required": ["file_paths"] },
{ "required": ["image_url"] },
{ "required": ["image_urls"] }
],
"additionalProperties": false
}
```
可同时提供本地路径和远程 URL。对应命令行参数:
- `--file_path <本地图片路径>`:可重复传入。
- `--file_paths <JSON数组>`:一次传入多个本地图片路径。
- `--image_url <远程图片URL>`:可重复传入。
- `--image_urls <JSON数组>`:一次传入多个远程图片 URL。
- `--send_original` 请求发送静态原图,也可以显式传 `--send_original true` 或 `--send_original false`。
## 执行
在技能目录运行脚本:
```bash
python3 scripts/send_image.py --file_path '/tmp/example.png'
```
发送静态原图或本地 GIF 的示例
```bash
python3 scripts/send_image.py --file_path '/tmp/photo.jpg' --send_original
python3 scripts/send_image.py --file_path '/tmp/reaction.gif'
```
发送远程图片:
```bash
python3 scripts/send_image.py --image_urls '["https://example.com/a.png","https://example.com/b.jpg"]'
```
本地图片逐个调用 `POST /api/v1/robot/message/send/image/local`;远程图片合并调用 `POST /api/v1/robot/message/send/image/url`。接收方固定读取 `ROBOT_FROM_WX_ID`,客户端端口读取 `ROBOT_WECHAT_CLIENT_PORT`。
## 约束
- 至少提供一个非空本地路径或远程 URL。
- 本地路径必须指向已存在且非空的文件,不能把 URL 作为本地路径传入。
- 远程 URL 必须包含有效的 `http` 或 `https` 协议及主机名。
- 脚本按首次出现顺序去重;所有参数通过校验后,单个发送失败时会继续尝试其余图片,最终返回全部失败原因。
## 输出
- 全部成功时输出「图片发送成功」,无需再发送额外消息。
- 任一失败时返回具体错误信息,不要声称图片已全部发送。