E
E
etozhesano2021-02-11 15:03:05
PowerShell
etozhesano, 2021-02-11 15:03:05

How to create a poll in Telegram via API?

Good afternoon everyone. There is such a situation: mailing to groups in telegrams is done through PowerShell, the code is as follows:

$URI = "https://api.telegram.org/bot" + $token + "/sendMessage?chat_id=" + $chat_id + "&text=" + $text
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Request = Invoke-WebRequest -URI ($URI)


Messages are sent successfully. Now the task, in addition to messages, is to send questionnaires. Is there any way to do this through the browser API?

UPD:

I figured out what is needed through SendPoll, but I can’t adequately formulate the JSON object. I am attaching the code below:

$token = "213"
$chat_id = @('2211', '31122', '3122')
$text = "Посмотрел?"
$options = @('Да', 'Нет')
$json = $options | ConvertTo-Json


foreach($chat_id_new in $chat_id) {

$URI = "https://api.telegram.org/bot" + $token + "/sendPoll?chat_id=" + $chat_id_new + "&question=" + $text + "&options" + $json
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Request = Invoke-WebRequest -URI ($URI)
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
robprane, 2021-02-11
@robprane

Use the appropriate method:
https://core.telegram.org/bots/api#sendpoll

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question