360 Secure SkillHub
360 安全技能中心

telegram-send-photo

提供 Python 示例脚本,使用 requests 读取本地图片并通过 Telegram Bot API 发送到指定聊天,可附加说明文字;需准备机器人令牌与目标聊天 ID。示例含明文凭据,且缺少异常处理、重试与图片限制说明。

suileyan
suileyan
热度 73.16
最近更新 2026-05-18 12:07:59
分类:自动化依赖:代码执行 / 读写文件 / 第三方 API应用场景:自动化脚本 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add telegram-send-photo
Metadata
name
telegram-send-photo
description
Send photos via Telegram Bot API.

Description

This skill allows sending image files to Telegram using the Bot API. Useful for sharing screenshots, images, or any visual content through Telegram.

Requirements

  • Python 3.x
  • requests library (pip install requests)
  • Telegram Bot Token
  • Target Chat ID

Usage

Python Script

import requests

# Configuration
bot_token = "YOUR_BOT_TOKEN"
chat_id = "YOUR_CHAT_ID"
photo_path = "path/to/image.png"

# Send photo
url = f"https://api.telegram.org/bot{bot_token}/sendPhoto"
files = {"photo": open(photo_path, "rb")}
data = {"chat_id": chat_id, "caption": "图片描述"}
resp = requests.post(url, files=files, data=data)

# Check response
if resp.status_code == 200:
    print("Photo sent successfully!")
else:
    print(f"Failed: {resp.text}")

Key Points

  1. Open image in binary mode ("rb")
  2. chat_id is required
  3. Use caption for optional description
  4. Handle encoding issues for special characters

Configuration

  • Bot Token: 8610746914:AAHvbRYhGar_DD81-70IeWSSfkDLyvrWKY0
  • Chat ID: 8422738233
  • Photo Storage: D:\mimoTool\photo\

Files

  • telegram_send_photo.py - Main script

Example

# Send a screenshot
photo_path = "D:\\mimoTool\\photo\\20260225_103159.png"
send_photo(photo_path, caption="截图")