Install
openclaw skills install tg-file-senderSend local files directly to Telegram chat. Supports documents, photos, and other media types. Use when user says: "send this file to me", "send to telegram", "把文件发给我", "通过tg发送", or any request to deliver a workspace file via Telegram. Handles file path resolution, size validation, and secure token management.
openclaw skills install tg-file-senderSend local files directly to a Telegram chat using the Bot API. The bot token is read from environment variable TG_BOT_TOKEN — never hardcoded or logged.
TG_BOT_TOKEN environment variable must be setcurl must be availableAccept a file path from the user. Resolve it relative to the workspace:
FILE_PATH="<workspace>/<user-provided-path>"
Security rules:
realpathUse the file extension to determine the appropriate Telegram method:
| Extension | Method | Caption support |
|---|---|---|
.jpg .jpeg .png .gif .webp | sendPhoto | ✅ Yes |
.mp4 .mov .avi .webm | sendVideo | ✅ Yes |
.mp3 .ogg .wav .flac | sendAudio | ✅ Yes |
Others (.xlsx, .pdf, .md, .zip, etc.) | sendDocument | ✅ Yes |
BOT_TOKEN="$TG_BOT_TOKEN"
CHAT_ID="<target chat ID>"
FILE_PATH="<resolved absolute path>"
CAPTION="<optional description>"
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendDocument" \
-F chat_id="$CHAT_ID" \
-F document=@"$FILE_PATH" \
-F caption="$CAPTION"
For photos:
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendPhoto" \
-F chat_id="$CHAT_ID" \
-F photo=@"$FILE_PATH" \
-F caption="$CAPTION"
Parse the JSON response:
ok: true → confirm delivery: "✅ 文件已发送"ok: false → report the description field to the user$TG_BOT_TOKEN only in the API call URL.realpath and verify the result starts with the workspace root.chat_id from the session context. Never prompt the user for a chat ID./tmp/, clean up after sending.TG_BOT_TOKEN is unset → tell the user: "请先设置 TG_BOT_TOKEN 环境变量"通过 Telegram Bot API 将本地文件直接发送到聊天窗口。Bot Token 从环境变量 TG_BOT_TOKEN 读取,绝不硬编码或写入日志。
TG_BOT_TOKEN 环境变量curl接收用户提供的路径,相对于工作目录解析:
FILE_PATH="<workspace>/<用户提供的路径>"
安全检查:
realpath 解析为绝对路径根据扩展名选择发送方式:
| 扩展名 | 方法 | 支持标题 |
|---|---|---|
.jpg .jpeg .png .gif .webp | sendPhoto | ✅ 是 |
.mp4 .mov .avi .webm | sendVideo | ✅ 是 |
.mp3 .ogg .wav .flac | sendAudio | ✅ 是 |
其他(.xlsx .pdf .md .zip 等) | sendDocument | ✅ 是 |
BOT_TOKEN="$TG_BOT_TOKEN"
CHAT_ID="<目标聊天ID>"
FILE_PATH="<解析后的绝对路径>"
CAPTION="<可选描述>"
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendDocument" \
-F chat_id="$CHAT_ID" \
-F document=@"$FILE_PATH" \
-F caption="$CAPTION"
解析 JSON 响应:
ok: true → 确认发送:"✅ 文件已发送"ok: false → 向用户展示 description 字段中的错误信息$TG_BOT_TOKENrealpath 解析,验证结果以工作目录开头TG_BOT_TOKEN 未设置 → "请先设置 TG_BOT_TOKEN 环境变量"