Meet Heyoo — an Open-source Python Wrapper for WhatsApp Cloud API | by Christopher Collins | May, 2022

Programming WhatsApp is now even simpler for Python builders

Photograph by Eyestetix Studio on Unsplash

WhatsApp is a free multiplatform messaging program that lets you make video and cellphone conversations, ship textual content messages, and extra all around the web. WhatsApp is extraordinarily widespread amongst family and friends who reside in different international locations and want to keep in contact, with over 2 billion lively customers.

WhatsApp lately opened up its Cloud API to make it simpler for builders to combine with its messaging service, however getting began could also be tough.

Heyoo is an open-source Python wrapper developed by Neurotech to make the combination even simpler.

  • Message sending
  • Media Distribution (pictures, audio, video and paperwork)
  • Ship location
  • Ship interactive buttons
  • Ship message templates

To start utilizing heyoo, you will need to first set up the library, both manually or utilizing pip.

You’ll be able to clone the venture repository with git or instantly obtain it as indicated beneath.

$ git clone https://github.com/Neurotech-HQ/heyoo
$ cd heyoo
heyoo $ python setup.py set up
# For Home windows 

pip set up --upgrade heyoo

#For Linux | MAC

pip3 set up --upgrade heyoo

To run the code on this bundle you’ll need a TOKEN and a TEST WHATSAPP NUMBER.

You’ll have to setup a Fb developer account on the Facebook Developer Portal the place you’ll later be prompted to setup a Fb enterprise account.

https://developers.facebook.com/

Some tips to get began.

  • Go to your purposes.
  • Create an utility
  • Select Enterprise >> Bussiness: You may be requested to fill out some primary app data.
  • Subsequent you may be prompted to incorporate merchandise in your app. WhatsApp Messenger ought to be included.
  • After making a enterprise account you’ll discover your TOKEN and TEST WHATSAPP NUMBER proper there.
  • Lastly, double-check the quantity you’ll use for testing within the To discipline.
  • After you’ve accomplished the previous steps, you’re prepared to start hacking with the Wrapper.

How you can authenticate your utility.

from heyoo import WhatsApp
messenger = WhatsApp('TOKEN', phone_number_id='104xxxxxx')

Upon getting authenticated your app, now you can begin utilizing the above-mentioned function as proven above.

Right here is tips on how to ship messages:

messenger.send_message('Your message ', 'xxxxxxxxxxx') # put cell quantity the place there's xxxxxxxxxxx
messenger.send_message('Hello there simply testing', 'xxxxxxxxxxx') # put cell quantity the place there's xxxxxxxxxxx

You’ll be able to both specify a hyperlink containing the media or specify an object id when transmitting media (picture, video, audio, gif, and doc) utilizing the identical technique.

All media strategies assume you’re sending a hyperlink with media by default, however you could change that by specifying hyperlink=False.

messenger.send_image(picture="https://i.imgur.com/Fh7XVYY.jpeg",
recipient_id="255757xxxxxx",)
messenger.send_video(video="https://www.youtube.com/watch?v=K4TOrB7at0Y",recipient_id="255757xxxxxx",)

Right here is an instance:

>>> messenger.send_audio(
audio="https://www.soundhelix.com/examples/mp3/SoundHelix-Track-1.mp3",
recipient_id="255757xxxxxx",
)
messenger.send_document(
doc="http://www.africau.edu/pictures/default/pattern.pdf",
recipient_id="255757xxxxxx",
)
messenger.send_location(
lat=1.29,
lengthy=103.85,
title="Singapore",
handle="Singapore",
recipient_id="255757xxxxxx",
)
messenger.send_button(
recipient_id="255757xxxxxx",
button=
"header": "Header Testing",
"physique": "Physique Testing",
"footer": "Footer Testing",
"motion":
"button": "Button Testing",
"sections": [

"title": "iBank",
"rows": [
"id": "row 1", "title": "Send Money", "description": "",

"id": "row 2",
"title": "Withdraw money",
"description": "",
,
],

],
,
,
)

Right here is tips on how to ship a pre-approved template message.

messenger.send_template("hello_world", "255757xxxxxx")

More Posts