Free Python Script to Build WhatsApp AI Chatbot with Gemini & WaSenderAPI

Free Python Script to Build a Smart WhatsApp AI Chatbot Using Gemini and WaSenderAPI ($6 Setup)
Excerpt: Looking to build your own AI chatbot for WhatsApp without expensive API fees? This guide shows you how to use a free Python script, Google's Gemini AI, and WaSenderAPI to create a smart and responsive WhatsApp chatbot for just $6/month.
Why Build Your Own WhatsApp AI Chatbot?
Most WhatsApp chatbots require access to the official WhatsApp Business API, which can be expensive and complex to get approved. Thanks to open-source tools like WaSenderAPI and Google's Gemini AI, you can now deploy your own chatbot with advanced AI capabilities for a fraction of the cost. This solution is ideal for entrepreneurs, small businesses, and developers.
What You Will Need
- WaSenderAPI: Affordable WhatsApp gateway ($6/month)
- Gemini AI API: Free tier includes 1500 requests/month
- Python and Flask: For backend logic
- Ngrok or VPS: To expose your local server for testing or run in production
Key Features of This Chatbot
- Handles incoming WhatsApp messages using WaSenderAPI webhooks
- Generates AI replies using Google's Gemini API
- Supports text, images, audio, video, and document messages
- Maintains conversation history and context
- Smart message splitting for long responses
- Customizable AI personality via JSON file
- Easy configuration with environment variables
Step-by-Step Installation
1. Clone the GitHub Repository
Clone the open-source project from GitHub: whatsapp-python-chatbot
2. Set Up Your Python Environment
python3 -m venv venv
source venv/bin/activate # On Windows use venv\Scripts\activate
pip install -r requirements.txt
3. Configure Environment Variables
Create a .env
file in the root directory and add:
GEMINI_API_KEY="your_gemini_api_key"
WASENDER_API_TOKEN="your_wasender_token"
FLASK_RUN_PORT=5001
4. Start the Flask Server
python3 script.py
This runs the chatbot locally on http://0.0.0.0:5001
5. Use Ngrok for Testing Webhooks
ngrok http 5001
Copy the public URL (e.g., https://xxxx.ngrok.io
) and paste it into the webhook section in your WaSenderAPI dashboard. Make sure to append /webhook
to the end.
Deploy to Production (Optional)
Use Gunicorn for production deployment:
pip install gunicorn
gunicorn --workers 4 --bind 0.0.0.0:5001 script:app
For better performance and security, use a reverse proxy like Nginx in front of Gunicorn.
Customizing the Bot's Personality
Edit the persona.json
file to define how the AI should behave in conversations:
{
"name": "WhatsApp Assistant",
"base_prompt": "You are a helpful and concise AI assistant replying in a WhatsApp chat...",
"description": "You are a helpful WhatsApp assistant. Keep your responses concise and clear..."
}
Webhook Setup in WaSenderAPI
- Log into your WaSenderAPI dashboard
- Connect your phone to a session
- Set the webhook URL to your server endpoint (e.g.,
https://yourdomain.com/webhook
) - Enable only
message_upsert
in the event types - Save your changes
Why This Chatbot is Different
This solution avoids the high costs of the official WhatsApp Business API by using WaSenderAPI ($6/month). It also taps into Gemini AI's free tier for natural, intelligent responses. The result is a chatbot that’s smart, customizable, and incredibly cost-effective — all using free open-source code.
Final Thoughts
If you want to deploy a smart, AI-powered WhatsApp chatbot for customer service, sales, or automation — and you don’t want to spend hundreds on setup — this is the perfect solution. It’s simple, scalable, and can be up and running in under an hour.
Try it now using the script here: Free WhatsApp Python Chatbot Script
Related Posts

Unofficial WhatsApp API: Affordable, Flexible & Reliable Alternative | WasenderAPI
Discover the benefits of using an unofficial WhatsApp API for businesses and developers. Compare costs, features, and stability, and see why WasenderAPI is the best low-cost solution with unlimited messages and easy integration.

Waapi Login Not Working? Best Alternative for WhatsApp API (WasenderAPI)
Searching for Waapi login but the site is down? Waapi is no longer working. Discover WasenderAPI, the best unofficial WhatsApp API alternative with reliable service.

Evolution API Pricing: Why WasenderAPI is a cheaper, | Cheap Alternative to evolution api
Discover how Evolution API pricing works and why WasenderAPI offers a more transparent, cost-effective solution. Save money with unlimited messages, no hidden fees, and easy multi-session WhatsApp integration. Switch today for hassle-free messaging.