sendSharedWidget
Gửi lại widget dùng chung do bot tạo (Bot API 10.4).
Giá trị trả về: Nếu thành công, trả về Message.
Tham số
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
chat_id | Integer or String | Có | ID chat hoặc @username |
message_thread_id | Integer | Tùy chọn | ID chủ đề diễn đàn |
widget_id | String | Có | ID widget dùng chung (widget.id từ tin nhắn đã gửi) |
chat_data | String | Tùy chọn | Trạng thái của widget trong chat này (chat_data), 0-1024 byte |
caption | String | Tùy chọn | Chú thích (0-1024) |
parse_mode | String | Tùy chọn | HTML, Markdown, MarkdownV2 |
caption_entities | Array of MessageEntity | Tùy chọn | Mảng JSON MessageEntity cho chú thích |
show_caption_above_media | Boolean | Tùy chọn | Hiển thị chú thích phía trên widget |
disable_notification | Boolean | Tùy chọn | Gửi không âm thanh |
protect_content | Boolean | Tùy chọn | Bảo vệ nội dung |
allow_paid_broadcast | Boolean | Tùy chọn | Cho phép gửi hàng loạt trả phí |
message_effect_id | String | Tùy chọn | ID hiệu ứng tin nhắn |
reply_parameters | ReplyParameters | Tùy chọn | Đối tượng JSON ReplyParameters |
reply_markup | InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply | Tùy chọn | JSON: InlineKeyboardMarkup / ReplyKeyboardMarkup / ReplyKeyboardRemove / ForceReply |
Ví dụ request
curl
curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendSharedWidget" \
-H "Content-Type: application/json" \
-d '{"chat_id":123456789,"widget_id":"WIDGET_ID"}'
Python
import requests
TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
f"https://api.telegram.org/bot{TOKEN}/sendSharedWidget",
json={
"chat_id": 123456789,
"widget_id": "WIDGET_ID"
},
timeout=30,
)
print(resp.json())
JavaScript
const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/sendSharedWidget`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"chat_id": 123456789,
"widget_id": "WIDGET_ID"
}),
});
console.log(await res.json());
Hướng dẫn từng bước: Ví dụ widget Telegram: HTML hoàn chỉnh và code bot Python
Phương thức liên quan
sendWidgetGửi tin nhắn có widget HTML (Bot API 10.4).answerWidgetQueryTrả lời truy vấn từ widget (Bot API 10.4).editMessageWidgetDataChỉnh sửa dữ liệu của widget trong tin nhắn (Bot API 10.4).editSharedWidgetDataChỉnh sửa dữ liệu công khai của widget dùng chung (Bot API 10.4).