Receive Response from a Button Message

Overview

This guide covers how to receive webhook response when a user clicks on a interactive button message you sent.

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a Go development environment.

You must have an onboarded WhatsApp account to receive inbound messages. If a number is listed as connected, it can receive inbound messages.

Create a Go server to receive messages.

Create a file called receive_whatsapp.go and paste into it this code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package main

import (
	"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
	fromnumber := r.FormValue("From")
	tonumber := r.FormValue("To")
	media := r.FormValue("Media1")
	print("Message Received - ", fromnumber, " ", tonumber, " ", media)
}

func main() {
	http.HandleFunc("/receive_whatsapp/", handler)
	http.ListenAndServe(":8080", nil)
}

Configure a webhook URL in your WhatsApp Business Account

Add or update a webhook URL from this link to a WhatsApp Business Account. Once you’ve done this, you should be able to receive inbound messages.

Test

Send a WhatsApp message to the Plivo number you specified using WhatsApp application.