Two-Way WhatsApp Messaging with Python
A quick walk-through on how to send Two-way messages with Sendchamp WhatsApp API using Python
Aliyu Abubakar
Aug 13, 2021
Learn how to quickly send a Two-way WhatsApp Message with Python using sendchamp API.
In this guide we will walk you through:
- Signing up free Sendchamp account
- Activate WhatsApp Number
- Setting up a Python Application
- Sending your WhatsApp Message
Prerequisite
Before you can get started, you need the following already set up:
- Python and a familiarity with how to create a new app.
- A sendchamp account
- Activated WhatsApp Number
Signing up free sendchamp account
If you Already have an account? skip to the next section. You can sign up for a free sendchamp account here.
When you sign up, you'll have to verify your email address. This allows sendchamp to verify your identity.
After you've verified your email address, you'll be asked a question in order to get you started in a way that's relevant to you.
After you finish setting up your account, you'll have access to your dashboard where you can access your API Key and perform dashboard communication functions.
Active a WhatsApp Number
Visit your sendchamp dashboard and navigate to WhatsApp channel.
Click on activate number and choose a subscription plan that is suitable for you. You won’t be asked to pay for it until your number is active.
When you select a plan, you’ll be redirected to a page that would ask you to fill in the necessary information. Basic information, WhatsApp account information and your business information.
Setting up a Python Application
First, you’ll need to create a file send.py
to save your code.
import requests
url = "https://api.sendchamp.com/api/v1/whatsapp/message/send"
payload="{\n \"recipient\": [\"2348055372961\"],\n
\"message\": \"Hello from Olumide Latest\",\n
\"type\": \"text\",\n
\"sender\": \"2348055372961\"\n}"
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer SECRET_KEY',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Replace URL with either a test or live BASE URL depending on what you intend to do.
Replace Authorization under HEADER with your test or live Access key depending on what you intend to do.
Parameters
- Set the recipient to the destination number.
- Set the value of the sender to your activated WhatsApp number.
- Set type to text
Sending your WhatsApp Message
Now you can execute the code and send your WhatsApp message.
Run the following script:
send.py
The code you used in the send.py file sends a POST request to the sendchamp API endpoint to send your WhatsApp message.