This guide covers how to receive WhatsApp media messages on a phone number registered to your WhatsApp Business Account.
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 Python 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 file called receive_whatsapp.py
and paste into it this code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from flask import Flask, request
app = Flask(__name__)
@app.route('/receive_whatsapp/', methods=['GET', 'POST'])
def inbound_sms():
from_number = request.values.get('From')
to_number = request.values.get('To')
media = request.values.get('Media1')
print('Message received - From: %s, To: %s, Text: %s' %(from_number, to_number, media))
return 'Message Recevived'
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
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.
Send a WhatsApp message to the Plivo number you specified using WhatsApp application.