SendPoll#
This method is intended for sending messages with a poll to a private or group chat. The message will be added to the send queue. The message is stored for 24 hours in the queue and will be sent immediately after phone authorization. The rate of message dispatch from the queue is governed by the message sending interval parameter.
To receive incoming notifications about poll messages, you need to enable the settings using one of the following options:
- Through console enable the settings
Get notifications about incoming messages and files
andGet notifications about surveys
- Through the SetSettings method enable the settings
incomingWebhook
andpollMessageWebhook
Request#
To send, you need to make a request to the address:
{{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 | Message text. Emoji characters 😃 are supported. The maximum length of the message text is 255 characters. |
options | array | Yes | Array of poll options. The number of answer options in a poll cannot be more than 12. Answer options must be different from each other by at least one symbol. |
multipleAnswers | boolean | No | Allow multiple answers. true - enabled, false - disabled, default: false |
quotedMessageId | string | No | If specified, the message will be sent quoting the specified chat message |
options
array fields:
Parameter | Type | Description |
---|---|---|
optionName | string | Poll choice option text. The maximum text length is 100 characters. |
Example of Request Body#
Number of answers options
To successfully send a poll, the number of answer options must be at least 2 and no more than 12.
Sending a message to a private chat:
{
"chatId": "11001234567@c.us",
"message": "Please choose the color:",
"options": [
{"optionName": "green"},
{"optionName": "red"},
{"optionName": "blue"}
],
"multipleAnswers": false,
}
Response#
Response Fields#
Field | Type | ОписанDescriptionие |
---|---|---|
idMessage | string | Identifier of the sent message |
Example of Response Body#
{
"idMessage": "3EB0C767D097B7C7C030"
}
Example of Display for the Receiver#
SendPoll errors#
For a list of errors common to all methods, refer to Common errors section
HTTP code | Error identifier | Description |
---|---|---|
400 | Bad Request Validation failed | Validation error |
400 | Validation failed. Details: Validation failed. Details: 'message' length must be less than or equal to 255 characters long | 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 length of the answer option must be less than or equal to 100 characters |
400 | Validation failed. Details: 'options[X].optionName' is required | Incorrect key for answer option X |
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 | Answer options must not be repeated |
500 | request entity too large | Json length exceeded (>100kb) |
Sending with invalid Quoted message ID
If the quotedMessageId
is specified incorrectly, the system will return code 200 and the id of the message, but it will not be delivered to the recipient.
Request examples#
import requests
url = "{{apiUrl}}/waInstance{{idInstance}}/sendPoll/{{apiTokenInstance}}"
payload = {
"chatId": "11001234567@c.us",
"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": "11001234567@c.us",
"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"":""71234567890@c.us"",""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