help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
whatsapp-chatbot
RSK World
whatsapp-chatbot
WhatsApp Chatbot - Python Flask + Twilio + Admin Dashboard + Multilingual Support + Sentiment Analysis + Booking Management
whatsapp-chatbot
  • __pycache__
  • static
  • templates
  • tests
  • .env418 B
  • .gitignore76 B
  • LICENSE1.5 KB
  • Procfile23 B
  • README.md5.4 KB
  • analytics.json10 B
  • app.py2.5 KB
  • bookings.json10 B
  • bot_logic.py10.9 KB
  • requirements.txt104 B
  • runtime.txt16 B
  • whatsapp-chatbot.png624.8 KB
QUICKSTART.mdapp.py
app.py
Raw Download
Find: Go to:
# Project: WhatsApp Chatbot
# Author: RSK World
# Email: info@rskworld.com, support@rskworld.com
# Website: https://rskworld.in
# Phone: +91 93305 39277
# Year: 2026
# Description: WhatsApp-integrated chatbot for business messaging and customer engagement.

from flask import Flask, request, render_template, jsonify, send_file
from twilio.twiml.messaging_response import MessagingResponse
from bot_logic import process_message, load_bookings, get_analytics_data
import os
import csv
import io
from datetime import datetime

app = Flask(__name__)

@app.route("/")
def home():
    """Renders the landing page for the WhatsApp Chatbot demo."""
    return render_template("index.html")

@app.route("/admin")
def admin():
    """Renders the Admin Dashboard."""
    bookings = load_bookings()
    return render_template("admin.html", bookings=bookings)

@app.route("/api/analytics")
def analytics():
    """API endpoint for dashboard charts."""
    return jsonify(get_analytics_data())

@app.route("/api/export_bookings")
def export_bookings():
    """Exports bookings to CSV."""
    bookings = load_bookings()
    
    # Create CSV in memory
    si = io.StringIO()
    cw = csv.writer(si)
    cw.writerow(["Timestamp", "Name", "Phone", "Preferred Date", "Topic"])
    
    for b in bookings:
        cw.writerow([b.get("timestamp"), b.get("name"), b.get("phone"), b.get("date"), b.get("topic")])
        
    output = io.BytesIO()
    output.write(si.getvalue().encode('utf-8'))
    output.seek(0)
    
    filename = f"bookings_{datetime.now().strftime('%Y%m%d')}.csv"
    return send_file(output, mimetype="text/csv", as_attachment=True, download_name=filename)

@app.route("/api/broadcast", methods=["POST"])
def broadcast():
    """Simulates sending a broadcast message."""
    data = request.json
    message = data.get("message", "")
    # In a real app, you would iterate over a User DB and call Twilio API here.
    return jsonify({"status": "success", "count": 142}) # Simulated count

@app.route("/webhook", methods=["POST"])
def webhook():
    """Receives incoming WhatsApp messages from Twilio."""
    incoming_msg = request.values.get('Body', '').lower()
    sender = request.values.get('From', '')

    response = MessagingResponse()
    msg = response.message()
    
    # Process the message and get the reply text
    reply_text = process_message(incoming_msg, sender)
    msg.body(reply_text)

    return str(response)

if __name__ == "__main__":
    app.run(debug=True, port=5000)
80 lines•2.5 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer