Telegram Bot API
🌐 中文

sendInvoice

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

发送支付账单。

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

参数

参数类型必填说明
chat_idInteger or String是聊天 ID 或 @username
message_thread_idInteger可选论坛话题 ID
direct_messages_topic_idInteger可选私信话题 ID (Bot API 10.0)
titleString是商品名称(1-32)
descriptionString是商品描述(1-255)
payloadString是有效载荷
provider_tokenString可选支付提供商令牌
currencyString是货币(Stars 使用 XTR)
pricesArray of LabeledPrice是LabeledPrice JSON 数组
max_tip_amountInteger可选最高小费金额
suggested_tip_amountsArray of Integer可选建议小费金额的 JSON 数组
start_parameterString可选支付深度链接
provider_dataString可选提供给支付提供商的 JSON 数据
photo_urlString可选商品照片 URL
photo_sizeInteger可选照片大小
photo_widthInteger可选照片宽度
photo_heightInteger可选照片高度
need_nameBoolean可选要求填写用户姓名
need_phone_numberBoolean可选要求填写电话号码
need_emailBoolean可选要求填写电子邮箱
need_shipping_addressBoolean可选要求填写收货地址
send_phone_number_to_providerBoolean可选将电话号码发送给支付提供商
send_email_to_providerBoolean可选将电子邮箱发送给支付提供商
is_flexibleBoolean可选可变运费
disable_notificationBoolean可选静默发送
protect_contentBoolean可选保护内容
allow_paid_broadcastBoolean可选允许付费广播
message_effect_idString可选消息特效 ID
suggested_post_parametersSuggestedPostParameters可选SuggestedPostParameters JSON 对象(用于频道)
reply_parametersReplyParameters可选ReplyParameters JSON 对象
reply_markupInlineKeyboardMarkup可选JSON 对象:InlineKeyboardMarkup

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

请求示例

curl

curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendInvoice" \
  -H "Content-Type: application/json" \
  -d '{
  "chat_id": 123456789,
  "title": "Example",
  "description": "Example item",
  "payload": "order-1",
  "currency": "XTR",
  "prices": [
    {
      "label": "Item",
      "amount": 100
    }
  ]
}'

Python

import requests

TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
    f"https://api.telegram.org/bot{TOKEN}/sendInvoice",
    json={
        "chat_id": 123456789,
        "title": "Example",
        "description": "Example item",
        "payload": "order-1",
        "currency": "XTR",
        "prices": [
            {
                "label": "Item",
                "amount": 100
            }
        ]
    },
    timeout=30,
)
print(resp.json())

JavaScript

const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/sendInvoice`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "chat_id": 123456789,
    "title": "Example",
    "description": "Example item",
    "payload": "order-1",
    "currency": "XTR",
    "prices": [
      {
        "label": "Item",
        "amount": 100
      }
    ]
  }),
});
console.log(await res.json());

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