About • Getting Started • Other resources • Contribution and feature requests
This was a question I had two weeks ago (January 2024). I found it a huge pain to implement for another project and therefore started this small sandbox environment.
To save others the pain I decided to make this repo public. Ideally, I'd like to make the Readme a collection of other resources as well.
- No packages or third-party services (Twilio, Messagebird, etc.) to interact with WhatsApp
- Asynchronous calls using httpx
- Setting up a webhook using FastAPI
- Extracting the most important information out of a message (message, file type, timestamp etc.)
- Receiving and then downloading a voice memo, document or image
- Sending a text message
- Sending a text message with multiple options
- Sending a document, including how to first upload the media
- Set up your Whatsapp app at developers.facebook.com/apps and get all of your credentials. Dave Ebbelaar has a good video on this.
- Make sure you've sent a message to your personal WhatsApp and replied.
- Replace all values in
example.envwith your credentials from Meta. - Rename
example.envto.env
- Setup Ngrok
- Set up an Ngrok account and get your static domain. To work with a webhook you need to have a redirect in place. I used and recommend ngrok for this.
- Start ngrok (you might need to install it first, e.g. with brew) using
ngrok http http://localhost:8000 --domain=<YOUR-NGROK-STATIC-DOMAIN>.ngrok-free.app
- Start the app with
python -m myapp.main
- "How To Connect OpenAI To WhatsApp" (YouTube video) uses Flask (not asynchronous) by Dave Ebbelaar
- Meta's documentation is also useful (I didn't find this initially), but there are some small mistakes.
- [py-fastapi-facebook-webhook] is useful GitHub repo that I started with when I created this repo, but some components don't work with current package versions (e.g. httpx)
Please feel free to open a pull request to add more content (or improve the code). If you don't know how to do that but still want to contribute then you can send me an email to dominique [dot] c [dot] a [dot] paul [at] gmail [dot] com
Also, feel free to reach out if you are stuck or want to request a feature to be added.