Telegram Bot API

sendWidget

Category: Widgets · Bot API 10.5 · Official documentation

Version history: Added in Bot API 10.4

Sends a message with an HTML widget (Bot API 10.4).

Returns: On success, returns Message.

Parameters

ParameterTypeRequiredDescription
chat_idInteger or StringYesChat ID or @username
message_thread_idIntegerOptionalForum topic ID
htmlStringYesHTML code of the widget: 1-32768 bytes, at most 4096 bytes after zlib compression
widthIntegerOptionalWidget width in logical pixels (omit for the full width of the message)
heightIntegerOptionalWidget height in logical pixels, 50-600 (omit to fit the content)
public_dataStringOptionalPublic state of the widget (public_data), 0-1024 bytes — visible wherever the widget is shown
chat_dataStringOptionalState of the widget in this chat (chat_data), 0-1024 bytes
captionStringOptionalCaption (0-1024)
parse_modeStringOptionalHTML, Markdown, MarkdownV2
caption_entitiesArray of MessageEntityOptionalJSON MessageEntity array for caption
show_caption_above_mediaBooleanOptionalShow the caption above the widget
allow_queriesBooleanOptionalAllow the widget to send queries to the bot (widget_query)
is_sharedBooleanOptionalCreate a shared widget — it can be sent again with sendSharedWidget
disable_notificationBooleanOptionalSend silently
protect_contentBooleanOptionalProtect content
allow_paid_broadcastBooleanOptionalAllow paid broadcast
message_effect_idStringOptionalMessage effect ID
reply_parametersReplyParametersOptionalJSON ReplyParameters object
reply_markupInlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReplyOptionalJSON: InlineKeyboardMarkup / ReplyKeyboardMarkup / ReplyKeyboardRemove / ForceReply

Parameter descriptions are concise summaries; see the official documentation for the full text.

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