sendWidget
Envia uma mensagem com um widget HTML (Bot API 10.4).
Retorno: Em caso de sucesso, retorna Message.
Parâmetros
| Parâmetro | Tipo | Obrigatório | Descrição |
|---|---|---|---|
chat_id | Integer or String | Sim | Chat ID ou @username |
message_thread_id | Integer | Opcional | ID do tópico do fórum |
html | String | Sim | Código HTML do widget: 1-32768 bytes, no máximo 4096 bytes após compressão zlib |
width | Integer | Opcional | Largura do widget em pixels lógicos (omita para usar a largura total da mensagem) |
height | Integer | Opcional | Altura do widget em pixels lógicos, 50-600 (omita para ajustar ao conteúdo) |
public_data | String | Opcional | Estado público do widget (public_data), 0-1024 bytes — visível em todos os lugares onde o widget é exibido |
chat_data | String | Opcional | Estado do widget neste chat (chat_data), 0-1024 bytes |
caption | String | Opcional | Legenda (0-1024) |
parse_mode | String | Opcional | HTML, Markdown, MarkdownV2 |
caption_entities | Array of MessageEntity | Opcional | Array JSON de MessageEntity para a legenda |
show_caption_above_media | Boolean | Opcional | Mostrar legenda acima do widget |
allow_queries | Boolean | Opcional | Permitir que o widget envie consultas ao bot (widget_query) |
is_shared | Boolean | Opcional | Criar um widget compartilhado — pode ser reenviado com sendSharedWidget |
disable_notification | Boolean | Opcional | Enviar sem som |
protect_content | Boolean | Opcional | Proteger conteúdo |
allow_paid_broadcast | Boolean | Opcional | Permitir transmissão paga |
message_effect_id | String | Opcional | ID do efeito da mensagem |
reply_parameters | ReplyParameters | Opcional | Objeto JSON ReplyParameters |
reply_markup | InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply | Opcional | Objeto JSON: InlineKeyboardMarkup / ReplyKeyboardMarkup / ReplyKeyboardRemove / ForceReply |
Exemplo de requisição
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());
Guia passo a passo: Widgets do Telegram: blocos HTML interativos dentro das mensagens do bot
Métodos relacionados
sendSharedWidgetReenvia um widget compartilhado criado pelo bot (Bot API 10.4).answerWidgetQueryResponde a uma consulta de um widget (Bot API 10.4).editMessageWidgetDataEdita os dados de um widget em uma mensagem (Bot API 10.4).editSharedWidgetDataEdita os dados públicos de um widget compartilhado (Bot API 10.4).