Telegram Bot API
🌐 中文

uploadStickerFile

分类: 贴纸 · Bot API 10.3 · 官方文档

上传贴纸文件。

返回值: 调用成功时返回 File。

参数

参数类型必填说明
user_idInteger是用户 ID
stickerInputFile是贴纸文件(InputFile 或 file_id)
sticker_formatString是贴纸格式:static、animated、video

参数说明为简要概括,完整内容请参阅官方文档。

请求示例

curl

curl -s "https://api.telegram.org/bot$TOKEN/uploadStickerFile" \
  -F user_id=123456789 \
  -F sticker_format=static \
  -F sticker=@sticker.png

Python

import requests

TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
    f"https://api.telegram.org/bot{TOKEN}/uploadStickerFile",
    data={
        "user_id": 123456789,
        "sticker_format": "static"
    },
    files={"sticker": open("sticker.png", "rb")},
    timeout=30,
)
print(resp.json())

JavaScript

import { readFile } from "node:fs/promises";

const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const form = new FormData();
form.append("user_id", "123456789");
form.append("sticker_format", "static");
form.append("sticker", new Blob([await readFile("sticker.png")]), "sticker.png");
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/uploadStickerFile`, { method: "POST", body: form });
console.log(await res.json());

分步教程: Telegram 机器人教程:从零创建 Telegram 机器人并发送第一条消息