It's hacktoberfest and in light of this month I'd like to write about a prominent open source package, here are its stats:
- 8000+ downloads a month
- 107,000+ downloads in total
- 1000+ downloads per week
- 356 stars and counting
Pretty insane right? Best of all? It's home made. A great African package written by Kalebu Gwalugano. If you haven't do checkout his github, he has many interesting packages in the making.
The package itself is called Heyoo, a Python wrapper for the whatsapp cloud API. Basically if you want to automate Whatsapp with Python, this package is the go to.
The docs are self explanatory but I'll highlight on how to use it, lets get started.
Just like cooking you'll need some ingredients, and to work with Heyoo you will need a TOKEN and TEST WHATSAPP NUMBER which you can get from the Facebook Developer Portal with these steps:
- Go to your apps
- create an app
- Select Business >> Business
- It will prompt you to enter basic app informations
- It will ask you to add products to your app a. Add WhatsApp Messenger
- Right there you will see a your TOKEN and TEST WHATSAPP NUMBER and its
- Lastly verify the number you will be using for testing on the To field.
All set? Lets start cooking
We will make a simple bot that can send messages.
Caution!! Do note that in order to receive messages from the bot YOU MUST SEND THE FIRST MESSAGE, otherwise it won't work. Facebook policy 🤷♂️
We first start by authorizing our bot, supply the token key and phone_number_id as such:
from heyoo import Whatsapp messenger = Whatsapp(token='XXXX', phone_number_id='XXX')
And to send a message, use the send_message method:
messenger.send_message('I am the bot', '255678XXXXXX')
You should receive a message from the bot:
And that's it! The bot is working! Too easy right?
You can also do a bunch of things like sending images and videos, see these examples:
messenger.send_image( image="https://i.imgur.com/Fh7XVYY.jpeg", recipient_id="255678XXXXXX", )
Simply provide an image link and let heyoo do its thing! You might ask, what about video? Well let's see:
messenger.send_video( video="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4", recipient_id="255757xxxxxx", )
Too easy! Kalebu did a great job making this package as user friendly as possible. I suggest you go through the repo, its well documented and use it in your projects.
I hope you learned a few things, reach out to me for any feedback and suggestions via twitter @AviTheDev.