Telegram Bot API
🌐 中文

postStory

分类: 动态 · Bot API 10.3 · 官方文档

代表商业账户发布动态。

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

参数

参数类型必填说明
business_connection_idString是商业连接 ID
contentInputStoryContent是InputStoryContent JSON 对象
active_periodInteger是有效期(秒):21600、43200、86400 或 172800
captionString可选说明文字(0-2048)
parse_modeString可选HTML、Markdown 或 MarkdownV2
caption_entitiesArray of MessageEntity可选MessageEntity JSON 数组
areasArray of StoryArea可选StoryArea JSON 数组
post_to_chat_pageBoolean可选发布到聊天资料页
protect_contentBoolean可选保护内容

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

请求示例

curl

curl -s -X POST "https://api.telegram.org/bot$TOKEN/postStory" \
  -H "Content-Type: application/json" \
  -d '{
  "business_connection_id": "BUSINESS_CONNECTION_ID",
  "content": {
    "type": "photo",
    "photo": "attach://photo"
  },
  "active_period": 86400
}'

Python

import requests

TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
    f"https://api.telegram.org/bot{TOKEN}/postStory",
    json={
        "business_connection_id": "BUSINESS_CONNECTION_ID",
        "content": {
            "type": "photo",
            "photo": "attach://photo"
        },
        "active_period": 86400
    },
    timeout=30,
)
print(resp.json())

JavaScript

const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/postStory`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "business_connection_id": "BUSINESS_CONNECTION_ID",
    "content": {
      "type": "photo",
      "photo": "attach://photo"
    },
    "active_period": 86400
  }),
});
console.log(await res.json());

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