Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

WhatsApp API for developers
WhatsApp API for developers

Posted on • Edited on

     

Replacing interactive buttons in WhatsApp API

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 separatelyin 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 thePOST /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 requestsurl = "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 modeExit 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 modeExit 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 modeExit 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 understandsource code for you to implement in your survey response integration or bot:
https://github.com/Whapi-Cloud/whatsapp-api-send-poll-example

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
whapicloud profile image
WhatsApp API for developers
Stable Whatsapp API for developers and business owners who value their time and money. Fixed price no hidden fees, unlimited messages
  • Joined

Remember, if you have any questions or issues along the way, our support team is always here to help. We value every user and strive to ensure that your experience with our API is as smooth and efficient as possible.

CollapseExpand
 
raphaelvserafim profile image
Raphael Serafim
Software Developer | 8 Years Experience in API Development, Websites & Systems | Expert in PHP, Node.js, MySQL, AI, Linux, JavaScript, TypeScript, Blockchain, React Native & React JS
  • Location
    Toronto - Canada
  • Work
    Software Developer
  • Joined

I use the unofficialapi-wa.me, which is stable, well-documented, and easy to use

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Stable Whatsapp API for developers and business owners who value their time and money. Fixed price no hidden fees, unlimited messages
  • Joined

More fromWhatsApp API for developers

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp