answerCallbackQuery
Trả lời truy vấn callback.
Giá trị trả về: Nếu thành công, trả về True.
Tham số
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
callback_query_id | String | Có | ID truy vấn callback |
text | String | Tùy chọn | Nội dung thông báo (0-200) |
show_alert | Boolean | Tùy chọn | Hiển thị hộp thoại cảnh báo thay vì thông báo ngắn |
url | String | Tùy chọn | URL cần mở (URL trò chơi hoặc liên kết t.me) |
cache_time | Integer | Tùy chọn | Thời gian cache tính bằng giây |
Ví dụ request
curl
curl -s -X POST "https://api.telegram.org/bot$TOKEN/answerCallbackQuery" \
-H "Content-Type: application/json" \
-d '{"callback_query_id":"CALLBACK_QUERY_ID"}'
Python
import requests
TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
f"https://api.telegram.org/bot{TOKEN}/answerCallbackQuery",
json={
"callback_query_id": "CALLBACK_QUERY_ID"
},
timeout=30,
)
print(resp.json())
JavaScript
const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/answerCallbackQuery`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"callback_query_id": "CALLBACK_QUERY_ID"
}),
});
console.log(await res.json());
Hướng dẫn từng bước: API gửi tin nhắn Telegram: hướng dẫn sendMessage với curl, Python và JavaScript
Phương thức liên quan
answerInlineQueryTrả lời truy vấn inline.answerGuestQueryTrả lời truy vấn khách - chế độ khách (Bot API 10.0).answerWebAppQueryGửi kết quả tương tác Web App.answerChatJoinRequestQueryTrả lời truy vấn yêu cầu tham gia chat (Bot API 10.1).sendChatJoinRequestWebAppHiển thị Mini App cho truy vấn yêu cầu tham gia chat (Bot API 10.1).