Replacing interactive buttons in WhatsApp API

WhatsApp API for developers - Feb 28 - - Dev Community

Interactive buttons in WhatsApp are a very convenient tool for working with users.
Many observations have confirmed that it is easier for a customer to reply with one button than to type a reply in the usual way, accordingly, the conversion rate of responses can increase by 1.5 - 2 times. However, this feature is not available to every user, but only for WhatsApp business accounts that work via Meta Cloud API.

We have already told you separately in the article in detail about how our API differs from Cloud API Meta, what are the differences in general, what are the advantages of each gateway. So let's leave it to you to study it on your own and get straight to the point!

We are in favor of facilitating communication with users, so we offer you a profitable alternative - polls.
For the user, polls and interactive buttons are functionally similar. Surveys also require the user to click on the desired line, so this simplification is considered comfortable.

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:
https://whapi.readme.io/reference/sendmessagepoll

Sending a poll

Sending a poll is quite easy, you need a few parameters in the body of the request:

  1. 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).
  2. title - here specify the full message to the conversation partner, the text of your question.
  3. options - specify the user's response options. There can be from 2 to 12 of them.
  4. 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)
Enter fullscreen mode Exit fullscreen mode

Example of a message sent to a customer

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="
          }
        ]
Enter fullscreen mode Exit fullscreen mode

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": [
    "61399176983@s.whatsapp.net"
  ]
 }
Enter fullscreen mode Exit fullscreen mode

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:
https://github.com/Whapi-Cloud/whatsapp-api-send-poll-example

. . . . . . . . . . . . . . . .