Telegram Bot API
🌐 Tiếng Việt

sendPoll

Danh mục: Bình chọn · Bot API 10.3 · Tài liệu chính thức

Gửi bình chọn.

Giá trị trả về: Nếu thành công, trả về Message.

Tham số

Tham sốKiểuBắt buộcMô tả
business_connection_idStringTùy chọnID kết nối doanh nghiệp
chat_idInteger or StringCóID chat hoặc @username
message_thread_idIntegerTùy chọnID chủ đề diễn đàn
questionStringCóCâu hỏi (1-300 ký tự)
question_parse_modeStringTùy chọnChế độ định dạng câu hỏi: HTML, Markdown, MarkdownV2
question_entitiesArray of MessageEntityTùy chọnMảng JSON MessageEntity cho câu hỏi
optionsArray of InputPollOptionCóMảng JSON InputPollOption [{"text":"Option 1"},{"text":"Option 2"}]
is_anonymousBooleanTùy chọnBình chọn ẩn danh (mặc định true)
typeStringTùy chọnquiz hoặc regular
allows_multiple_answersBooleanTùy chọnCho phép chọn nhiều đáp án
allows_revotingBooleanTùy chọnCho phép bình chọn lại (Bot API 9.6)
shuffle_optionsBooleanTùy chọnXáo trộn các lựa chọn (Bot API 9.6)
allow_adding_optionsBooleanTùy chọnCho phép thêm lựa chọn (Bot API 9.6)
hide_results_until_closesBooleanTùy chọnẨn kết quả cho đến khi bình chọn kết thúc (Bot API 9.6)
members_onlyBooleanTùy chọnChỉ thành viên (Bot API 10.0)
country_codesArray of StringTùy chọnMảng JSON các mã quốc gia (Bot API 10.0)
correct_option_idsArray of IntegerTùy chọnMảng JSON các ID lựa chọn đúng (cho quiz), ví dụ [0]
explanationStringTùy chọnGiải thích đáp án đúng (cho quiz)
explanation_parse_modeStringTùy chọnChế độ định dạng phần giải thích
explanation_entitiesArray of MessageEntityTùy chọnMảng JSON MessageEntity cho phần giải thích
explanation_mediaInputPollMediaTùy chọnĐối tượng JSON InputPollMedia (Bot API 10.0)
open_periodIntegerTùy chọnThời gian mở bình chọn tính bằng giây (5-2628000)
close_dateIntegerTùy chọnMốc thời gian Unix đóng bình chọn
is_closedBooleanTùy chọnĐóng bình chọn ngay lập tức
descriptionStringTùy chọnMô tả bình chọn (0-1024 ký tự, Bot API 9.6)
description_parse_modeStringTùy chọnChế độ định dạng mô tả: HTML, Markdown, MarkdownV2
description_entitiesArray of MessageEntityTùy chọnMảng JSON MessageEntity cho phần mô tả
mediaInputPollMediaTùy chọnĐối tượng JSON InputPollMedia — media của bình chọn (Bot API 10.0)
disable_notificationBooleanTùy chọnGửi không âm thanh
protect_contentBooleanTùy chọnBảo vệ nội dung
allow_paid_broadcastBooleanTùy chọnCho phép gửi hàng loạt trả phí
message_effect_idStringTùy chọnID hiệu ứng tin nhắn
reply_parametersReplyParametersTùy chọnĐối tượng JSON ReplyParameters
reply_markupInlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReplyTùy chọnJSON: InlineKeyboardMarkup / ReplyKeyboardMarkup / ReplyKeyboardRemove / ForceReply

Mô tả tham số chỉ là bản tóm tắt ngắn gọn; xem tài liệu chính thức để đọc toàn văn.

Ví dụ request

curl

curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendPoll" \
  -H "Content-Type: application/json" \
  -d '{
  "chat_id": 123456789,
  "question": "Which language do you use?",
  "options": [
    {
      "text": "Python"
    },
    {
      "text": "JavaScript"
    }
  ]
}'

Python

import requests

TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
    f"https://api.telegram.org/bot{TOKEN}/sendPoll",
    json={
        "chat_id": 123456789,
        "question": "Which language do you use?",
        "options": [
            {
                "text": "Python"
            },
            {
                "text": "JavaScript"
            }
        ]
    },
    timeout=30,
)
print(resp.json())

JavaScript

const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/sendPoll`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "chat_id": 123456789,
    "question": "Which language do you use?",
    "options": [
      {
        "text": "Python"
      },
      {
        "text": "JavaScript"
      }
    ]
  }),
});
console.log(await res.json());

Hướng dẫn từng bước: Cách tạo bot Telegram từ A đến Z: BotFather, token và tin nhắn đầu tiên