SendPoll#
The method is intended for sending a message with a poll to a group chat.
The message is added to the sending queue.
The rate at which messages are sent from the queue is set by the message sending interval.
Request#
To send it, you need to execute a request at:
POST
{{apiUrl}}/waInstance{{idInstance}}/sendPoll/{{apiTokenInstance}}
To get the apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.
Request parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
chatId | string | Yes | Chat identifier |
message | string | Yes | Text of the poll question. Length from 1 to 255 characters. Emoji 😃 characters are supported |
options | array | Yes | Array of strings with answer options (from 2 to 12 options). |
type | string | No | Poll type. Available values: - regular (a regular poll), - quiz (a quiz).Default is regular |
multipleAnswers | boolean | No | Allow selecting several answer options, true/ false. Relevant only for the regular type, default: false |
isAnonymous | boolean | No | If true, the list of voters is hidden. Default: true. Non-anonymous polls cannot be sent to channels. |
correctOptionId | integer | No | Index of the correct answer (starting from 0). Used for polls of the quiz type |
quotedMessageId | string | No | Identifier of the quoted message |
typingTime | integer | No | The time the typing notification is displayed in the correspondent's chat. Takes a value in the range from 1000 to 20000 milliseconds (from 1 to 20 seconds) |
typingType | string | No | Typing type. Possible values: |
text - "typing..." (default) | |||
record_voice_note - "recording a voice message..." | |||
upload_voice_note - "sending a voice message..." | |||
record_video_note - "recording a video message..". | |||
upload_video_note - "sending a video message..." | |||
record_video - "recording a video..." | |||
upload_video - "sending a video..." | |||
upload_photo - "sending a photo..." | |||
upload_document - "sending a file..." | |||
choose_sticker - "choosing a sticker..." | |||
choose_location - "choosing a location..." | |||
choose_contact - "choosing a contact..." |
Fields of the options array
| Parameter | Type | Description |
|---|---|---|
optionName | string | Text of each answer option, from 1 to 100 characters. The options must differ from each other. |
Request body example#
Sending a message to a group chat#
{
"chatId": "-12345678909876",
"message": "Please choose the color:",
"options": [
{ "optionName": "green" },
{ "optionName": "red" },
{ "optionName": "blue" }
],
"multipleAnswers": false
}
Sending a quiz to a group chat#
{
"chatId": "@channel_username",
"message": "Which planet is the largest in the Solar System?",
"options": [
{ "optionName": "Mars" }, // optionId = 0
{ "optionName": "Venus" }, // optionId = 1
{ "optionName": "Jupiter" }, // optionId = 2
{ "optionName": "Saturn" } // optionId = 3
],
"type": "quiz",
"correctOptionId": 2,
"isAnonymous": false
}
Sending a message with quoting#
{
"chatId": "-12345678909876",
"message": "Please choose the color:",
"options": [
{ "optionName": "green" },
{ "optionName": "red" },
{ "optionName": "blue" }
],
"multipleAnswers": false,
"quotedMessageId": "1769676078000"
}
Response#
Response fields#
| Field | Type | Description |
|---|---|---|
idMessage | string | Identifier of the sent message |
Response body example#
{
"idMessage": "1769676078000"
}
Errors#
For the list of errors common to all methods, see the Common errors section
| HTTP code | Error identifier | Description |
|---|---|---|
| 400 | Bad Request Validation failed | Validation error |
| 400 | Validation failed. Details: 'message' length must be less than or equal to 255 characters long | The message length must be less than or equal to 255 characters |
| 400 | Validation failed. Details: 'optionName' length must be less than or equal to 100 characters long | The answer option length must be less than or equal to 100 characters |
| 400 | Validation failed. Details: 'options' length must be from 2 to 12 elements inclusive | Incorrect number of answer options |
| 400 | Validation failed. Details: 'optionName' field must have unique value | The answer options must not be repeated |
| 400 | Validation failed. Details: Polls can only be sent to groups or channels, not private chats | Polls can be sent only to group chats |
Code examples#
import requests
url = "{{apiUrl}}/waInstance{{idInstance}}/sendPoll/{{apiTokenInstance}}"
payload = {
"chatId": "-12345678909876",
"message": "Please choose the color:",
"options": [
{"optionName": "green"},
{"optionName": "red"},
{"optionName": "blue"}
],
"multipleAnswers": True
}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=payload, headers=headers)
print(response.text.encode('utf8'))
curl --location --request POST '{{apiUrl}}/waInstance{{idInstance}}/sendPoll/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"chatId": "-12345678909876",
"message": "Please choose the color:",
"options": [{"optionName": "green"}, {"optionName": "red"}, {"optionName": "blue"}]
}'
Sub SendPoll()
Dim url As String
Dim RequestBody As String
Dim http As Object
Dim response As String
' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
url = "{{apiUrl}}/waInstance{{idInstance}}/sendPoll/{{apiTokenInstance}}"
' chatId - chat identifier, message - message text, options - array of data about choice options, multipleAnswers - allow multiple answers. true - enabled, false - disabled, Default: false
RequestBody = "{""chatId"":""-12345678909876"",""message"":""Please choose the color:"",""options"":[{""optionName"":""green""},{""optionName"":""red""},{""optionName"":""blue""}],""multipleAnswers"":false}"
Set http = CreateObject("MSXML2.XMLHTTP")
With http
.Open "POST", url, False
.setRequestHeader "Content-Type", "application/json"
.send RequestBody
End With
response = http.responseText
Debug.Print response
' Outputting the answer to the desired cell
Range("A1").Value = response
Set http = Nothing
End Sub