How to use polls as buttons?
Creating polls as an alternative to interactive buttons in WhatsApp
Interactive buttons in WhatsApp are a very handy tool for working with customers.
In our API, you have the option to send messages with buttons: Read more
However, sometimes buttons may not fit in your scenario. That's why we offer you a convenient alternative - use polls as buttons.
For the user, polls and interactive buttons are functionally similar. And the mechanism of working with a poll is very similar to that of buttons.
To work with surveys, you will need to use the POST /messages/poll method. You can find out more about it and test it here:
You will find ready-made code snippets in popular programming languages at the link.
Sending a poll
Sending a poll is quite easy, you need a few parameters in the body of the request:
to
- in this parameter specify the Chat ID of the recipient (group, or personal number) to whom we send the survey. (Send only numbers, without formatting or masks).title
- here specify the full message to the conversation partner, the text of your question.options
- specify the user's response options. There can be from 2 to 12 of them.count
- this parameter affects the amount of response options from the conversation partner. For example, several or only one answer from the whole survey.
import requests
url = "https://gate.whapi.cloud/messages/poll"
payload = {
"options": ["Eyelash extensions", "Eyebrow correction and coloring", "Massage", "I'm fine with everything!"],
"title": "Thank you for visiting the Etteri salon! We are interested in ensuring that our beauty salon meets all your wishes. What service do you think is missing in our beauty salon?",
"count": 1
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": "Bearer YPZapY69pl9j0xQpxoMqqsKMoBat1p8h"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
Tracking a user's selection in a poll
Polls are of a customized type"type": "poll"
. At the same time, each option that can be voted for by the client also has its own identifier. For example:
"results": [
{
"name": "I'm good",
"voters": [],
"count": 0,
"id": "YCUAzJ4pYtRgSP+k/udEwRdvHxxuRQmNCrdTKz/K2TU="
},
{
"name": "Can't complain",
"voters": [],
"count": 0,
"id": "f61LjJqD6KEefNsuDQrvFXAB1iufPN3U1ykIOxD8DRc="
}
]
Whereas when you vote, the webhook will receive full details of the selected option in the poll.
{
"id": "f61LjJqD6KEefNsuDQrvFXAB1iufPN3U1ykIOxD8DRc=",
"name": "Can't complain",
"count": 1,
"voters": [
"[email protected]"
]
}
This way, you will be able to handle your customers' responses and respond appropriately. For example, responding with a pre-prepared answer.
Node.Js source code
We have prepared a simple and easy to understand source code for you to implement in your survey response integration or bot.
Last updated
Was this helpful?