Py-WhatsApp: Unofficial python module for chat api- 2 mins
Py-WhatsApp is the un-official python module for chat-api.com and provides a pure pythonic way to communicate with WhatsApp programmatically without the official business API.
What is chat-api.com
It is a multifunctional rest api for WhatsApp accounts working on top of WhatsApp web. They offer a 3-day free trial to allow you to use the service before buying and this python package allows you to interface with most of its services directly.
Pitfalls of official WhatsApp API
- You first need to get approved from WhatsApp to start using the business API.
- You are tied in with a third party provider to avail the services and has to pay their set prices which are generally low but depends on per incoming/outgoing message.
- When someone contacts your number, you have to reply with in 24 hours. Post that, you can only send a template message to the contact.
- You cannot send any message to a person who has not initiated a conversation with you, you can only send them a template message.
What is template message? This is a message which has to be first approved by WhatsApp and then you can use it to contact potential customers or reply to conversations which are older than 24 hours.
For more information head over to https://www.whatsapp.com/business/api/.
How to use
- Go to chat-api.com and create a new account.
- After successful account creation you will have a single instance active, copy the
tokenand keep them safe.
- Install the module using
pip install whatsapp-api.
Now use the following code snippet to send the message. Click here to read more in-depth details on using the library.
from whatsapp import WhatsApp token = "xxxxxxx" instance_id = "instancexxx" object = WhatsApp(token, instance_id) phone_number = "911234512345" message = "This is a sample text message. *This will be bold*" response = object.send_message(phone_number, message)
Keep in mind the phone number has to be in the international format, here the sample number is from India(country code +91).
I am in no way associated to WhatsApp to Chat-API. This post and the corresponding module is only for educational purpose.