This repository contains the source code for an AI-powered WhatsApp bot developed using Python and Flask. Leveraging the Meta (formerly Facebook) Cloud API, this project demonstrates how to create a responsive and interactive WhatsApp bot capable of real-time message processing and AI-driven responses.
A transparent discovery signal based on current public GitHub metadata.
Recent activity35% weight
10
Community adoption25% weight
15
Maintenance state20% weight
100
License clarity10% weight
100
Project information10% weight
35
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
README preview
Build AI WhatsApp Bots with Pure Python
This guide will walk you through the process of creating a WhatsApp bot using the Meta (formerly Facebook) Cloud API with pure Python and Flask. We'll also integrate webhook events to receive messages in real-time and use OpenAI to generate AI responses. For more information on the structure of the Flask application, you can refer to this documentation.
A business app — If you don't have one, you can learn to create a business app here. If you don't see an option to create a business app, select Other > Next > Business.
Familiarity with Python to follow the tutorial.
Python 3.6+ installed on your machine. Installation instructions can be found on the official Python website.
pip for installing Python packages. It comes pre-installed with Python 3.4 and later.
virtualenv or any Python environment manager of your choice (optional but recommended for isolating project dependencies).
ngrok for creating a secure tunnel to your localhost for webhook development (instructions included below).
This repository contains a 90-day cybersecurity study plan, along with resources and materials for learning various cybersecurity concepts and technologies. The plan is organized into daily tasks, covering topics such as Network+, Security+, Linux, Python, Traffic Analysis, Git, ELK, AWS, Azure, and Hacking. The repository also includes a `LEARN.md
Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.
On the System Users page, configure the assets for your System User, assigning your WhatsApp app with full control. Don't forget to click the Save Changes button.
Now click Generate new token and select the app, and then choose how long the access token will be valid. You can choose 60 days or never expire.
Select all the permissions, as I was running into errors when I only selected the WhatsApp ones.
Confirm and copy the access token.
Now we have to find the following information on the App Dashboard:
APP_ID: "<YOUR-WHATSAPP-BUSINESS-APP_ID>" (Found at App Dashboard)
APP_SECRET: "<YOUR-WHATSAPP-BUSINESS-APP_SECRET>" (Found at App Dashboard)
RECIPIENT_WAID: "" (This is your WhatsApp ID, i.e., phone number. Make sure it is added to the account as shown in the example test message.)
VERSION: "v18.0" (The latest version of the Meta Graph API)
ACCESS_TOKEN: "" (Created in the previous step)
You can only send a template type message as your first message to a user. That's why you have to send a reply first before we continue. Took me 2 hours to figure this out.
Step 3: Configure Webhooks to Receive Messages
Please note, this is the hardest part of this tutorial.
Start your app
Make you have a python installation or environment and install the requirements: pip install -r requirements.txt
ngrok will display a URL where your localhost application is exposed to the internet (copy this URL for use with Meta).
Integrate WhatsApp
In the Meta App Dashboard, go to WhatsApp > Configuration, then click the Edit button.
In the Edit webhook's callback URL popup, enter the URL provided by the ngrok agent to expose your application to the internet in the Callback URL field, with /webhook at the end (i.e. https://myexample.ngrok-free.app/webhook).
Enter a verification token. This string is set up by you when you create your webhook endpoint. You can pick any string you like. Make sure to update this in your VERIFY_TOKEN environment variable.
After you add a webhook to WhatsApp, WhatsApp will submit a validation post request to your application through ngrok. Confirm your localhost app receives the validation get request and logs WEBHOOK_VERIFIED in the terminal.
Back to the Configuration page, click Manage.
On the Webhook fields popup, click Subscribe to the messages field. Tip: You can subscribe to multiple fields.
If your Flask app and ngrok are running, you can click on "Test" next to messages to test the subscription. You recieve a test message in upper case. If that is the case, your webhook is set up correctly.
Testing the Integration
Use the phone number associated to your WhatsApp product or use the test number you copied before.
Add this number to your WhatsApp app contacts and then send a message to this number.
Confirm your localhost app receives a message and logs both headers and body in the terminal.
Test if the bot replies back to you in upper case.
You have now succesfully integrated the bot! 🎉
Now it's time to acutally build cool things with this.
Step 4: Understanding Webhook Security
Below is some information from the Meta Webhooks API docs about verification and security. It is already implemented in the code, but you can reference it to get a better understanding of what's going on in security.py
Anytime you configure the Webhooks product in your App Dashboard, we'll send a GET request to your endpoint URL. Verification requests include the following query string parameters, appended to the end of your endpoint URL. They will look something like this:
GET https://www.your-clever-domain-name.com/webhook?
hub.mode=subscribe&
hub.challenge=1158201444&
hub.verify_token=meatyhamhock
The verify_token, meatyhamhock in the case of this example, is a string that you can pick. It doesn't matter what it is as long as you store in the VERIFY_TOKEN environment variable.
This repository contains the solutions and explanations to the algorithm problems on LeetCode. Only medium or above are included. All are written in C++/Python and implemented by myself. The problems attempted multiple times are labelled with hyperlinks.