WasenderApi - Low Cost WhatsApp API for Developers Free Python Script to Build WhatsApp AI Chatbot with Gemini & WaSenderAPI - WasenderApi - Low Cost WhatsApp API for Developers
Back to all posts

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

WasenderAPI
5/29/2025
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

  1. Log into your WaSenderAPI dashboard
  2. Connect your phone to a session
  3. Set the webhook URL to your server endpoint (e.g., https://yourdomain.com/webhook)
  4. Enable only message_upsert in the event types
  5. 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

How to get whatsapp channel JID  | Complete Guide to Extract WhatsApp Channel ID
WhatsApp for Developers

How to get whatsapp channel JID | Complete Guide to Extract WhatsApp Channel ID

Learn how to retrieve the WhatsApp channel JID (Channel ID) using webhooks for seamless automation of message sending. This guide walks you through the process of setting up a webhook to capture JID, testing it with tools like Webhook.site, and sending automated messages. Perfect for anyone looking to integrate WhatsApp messaging in their automation workflows

WasenderAPI
4/24/2025
Unofficial WhatsApp API A Complete 2025 Guide for Developers and Businesses
WhatsApp for Developers

Unofficial WhatsApp API A Complete 2025 Guide for Developers and Businesses

Looking for a flexible, fast, and affordable unofficial WhatsApp API? Discover why WaSenderAPI is the best alternative to Meta’s limited official API in 2025.

WasenderAPI
7/11/2025
How to Send WhatsApp Messages from Google Sheets Automatically (2025 Guide)
Use Cases & AutomationWhatsApp API TutorialsWhatsApp for Developers

How to Send WhatsApp Messages from Google Sheets Automatically (2025 Guide)

Learn how to send WhatsApp messages from Google Sheets automatically using WasenderAPI. This comprehensive guide covers both Apps Script and no-code methods to streamline your business communication and save hours of manual work.

WasenderAPI
3/6/2026