sendWidget
Sends a message with an HTML widget (Bot API 10.4).
Returns: On success, returns Message.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
chat_id | Integer or String | Yes | Chat ID or @username |
message_thread_id | Integer | Optional | Forum topic ID |
html | String | Yes | HTML code of the widget: 1-32768 bytes, at most 4096 bytes after zlib compression |
width | Integer | Optional | Widget width in logical pixels (omit for the full width of the message) |
height | Integer | Optional | Widget height in logical pixels, 50-600 (omit to fit the content) |
public_data | String | Optional | Public state of the widget (public_data), 0-1024 bytes — visible wherever the widget is shown |
chat_data | String | Optional | State of the widget in this chat (chat_data), 0-1024 bytes |
caption | String | Optional | Caption (0-1024) |
parse_mode | String | Optional | HTML, Markdown, MarkdownV2 |
caption_entities | Array of MessageEntity | Optional | JSON MessageEntity array for caption |
show_caption_above_media | Boolean | Optional | Show the caption above the widget |
allow_queries | Boolean | Optional | Allow the widget to send queries to the bot (widget_query) |
is_shared | Boolean | Optional | Create a shared widget — it can be sent again with sendSharedWidget |
disable_notification | Boolean | Optional | Send silently |
protect_content | Boolean | Optional | Protect content |
allow_paid_broadcast | Boolean | Optional | Allow paid broadcast |
message_effect_id | String | Optional | Message effect ID |
reply_parameters | ReplyParameters | Optional | JSON ReplyParameters object |
reply_markup | InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply | Optional | JSON: InlineKeyboardMarkup / ReplyKeyboardMarkup / ReplyKeyboardRemove / ForceReply |
Example request
curl
curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendWidget" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 123456789,
"html": "<h3>Order #1042</h3><p>2 × Margherita</p><button>Track the order</button>"
}'
Python
import requests
TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
f"https://api.telegram.org/bot{TOKEN}/sendWidget",
json={
"chat_id": 123456789,
"html": "<h3>Order #1042</h3><p>2 × Margherita</p><button>Track the order</button>"
},
timeout=30,
)
print(resp.json())
JavaScript
const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/sendWidget`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"chat_id": 123456789,
"html": "<h3>Order #1042</h3><p>2 × Margherita</p><button>Track the order</button>"
}),
});
console.log(await res.json());
Step-by-step guide: Telegram Widgets: Interactive HTML Inside Bot Messages
Related methods
sendSharedWidgetSends again a shared widget created by the bot (Bot API 10.4).answerWidgetQueryAnswers a query from a widget (Bot API 10.4).editMessageWidgetDataEdits the data of a widget in a message (Bot API 10.4).editSharedWidgetDataEdits the public data of a shared widget (Bot API 10.4).