Telegram Bot API
🌐 中文

sendGift

分类: 支付 · Bot API 10.3 · 官方文档

向用户或聊天发送礼物。

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

参数

参数类型必填说明
user_idInteger可选用户 ID(user_id 或 chat_id)
chat_idInteger or String可选聊天 ID 或 @username(可替代 user_id)
gift_idString是礼物 ID
pay_for_upgradeBoolean可选支付礼物升级费用
textString可选礼物留言文本(0-255)
text_parse_modeString可选文本解析模式:HTML、Markdown、MarkdownV2
text_entitiesArray of MessageEntity可选MessageEntity JSON 数组

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

请求示例

curl

curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendGift" \
  -H "Content-Type: application/json" \
  -d '{"gift_id":"GIFT_ID"}'

Python

import requests

TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
    f"https://api.telegram.org/bot{TOKEN}/sendGift",
    json={
        "gift_id": "GIFT_ID"
    },
    timeout=30,
)
print(resp.json())

JavaScript

const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/sendGift`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "gift_id": "GIFT_ID"
  }),
});
console.log(await res.json());

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