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
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
restaurant-booking-bot
RSK World
restaurant-booking-bot
Restaurant Booking Bot - Python + Flask + SQLAlchemy + AI Chatbot + Reservations + Digital Menu
restaurant-booking-bot
  • static
  • templates
  • .gitignore78 B
  • LICENSE1.1 KB
  • README.md1.2 KB
  • app.py5.5 KB
  • models.py1.2 KB
app.py
app.py
Raw Download
Find: Go to:
"""
Restaurant Booking Bot - Main Application
Developer: Molla Samser (RSK World)
Designer & Tester: Rima Khatun
Website: https://rskworld.in
Year: 2026
MIT License (c) 2026 Molla Samser (RSK World)
"""

from flask import Flask, render_template, request, jsonify
from models import db, Reservation, Menu, Loyalty
import os

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///instance/restaurant.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db.init_app(app)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/demo')
def demo():
    return render_template('demo.html')

@app.route('/api/chat', methods=['POST'])
def chat():
    data = request.json
    message = data.get('message', '').lower()
    
    # Sentiment Analysis Keywords
    negative_words = ['bad', 'slow', 'horrible', 'angry', 'wait', 'cold', 'wrong']
    positive_words = ['great', 'good', 'amazing', 'love', 'excellent', 'thanks']
    
    sentiment = "neutral"
    if any(word in message for word in negative_words):
        sentiment = "negative"
    elif any(word in message for word in positive_words):
        sentiment = "positive"

    # Logic based on sentiment
    if sentiment == "negative":
        response = "I'm deeply sorry to hear about your experience. I've issued a 'Priority Token' for your next visit. How can I make it right today?"
    elif sentiment == "positive":
        response = "That's wonderful to hear! We love making our guests happy. Would you like to join our RSK Loyalty Program for exclusive rewards?"
    elif 'booking' in message or 'reserve' in message:
        response = "I can help you with that! Please provide your name, date, and time. You can also pick your favorite table from our visual map!"
    elif 'menu' in message or 'recommend' in message:
        response = "I'd love to recommend something! What's your mood today? (Spicy, Refreshing, Savory, or Sweet?)"
    elif 'spicy' in message:
        response = "For something spicy, I highly recommend our signature 'Fire-Roasted Chili Pasta' or 'Spicy Garlic Salmon'!"
    elif 'sweet' in message:
        response = "Got a sweet tooth? You must try our 'Chocolate Lava Cake' or 'Berry Blast Parfait'!"
    elif 'refreshing' in message:
        response = "Looking for something light? Our 'Mediterranean Caesar Salad' or 'Mint Lime Zest' is perfect!"
    elif 'savory' in message:
        response = "If you want something hearty, our 'Truffle Mushroom Risotto' is a guest favorite."
    else:
        response = f"I am the RSK Booking Bot. I can help with reservations, menu recommendations, and even detect how you're feeling! How can I assist?"
        
    return jsonify({"response": response, "sentiment": sentiment})

@app.route('/api/recommend', methods=['GET'])
def recommend():
    mood = request.args.get('mood', '').lower()
    recommendations = {
        "spicy": ["Fire-Roasted Chili Pasta", "Spicy Garlic Salmon"],
        "sweet": ["Chocolate Lava Cake", "Berry Blast Parfait"],
        "refreshing": ["Mediterranean Caesar Salad", "Mint Lime Zest"],
        "savory": ["Truffle Mushroom Risotto", "Grilled Ribeye"]
    }
    return jsonify(recommendations.get(mood, []))

@app.route('/api/reserve', methods=['POST'])
def reserve():
    data = request.json
    try:
        new_res = Reservation(
            name=data['name'],
            email=data['email'],
            date=data['date'],
            time=data['time'],
            guests=data['guests']
        )
        db.session.add(new_res)
        
        # Award loyalty points (10 points per reservation)
        user_loyalty = Loyalty.query.filter_by(email=data['email']).first()
        if not user_loyalty:
            user_loyalty = Loyalty(email=data['email'], points=10)
            db.session.add(user_loyalty)
        else:
            user_loyalty.points += 10
            
        db.session.commit()
        return jsonify({
            "status": "success", 
            "message": "Reservation confirmed! You earned 10 loyalty points.",
            "points": user_loyalty.points
        })
    except Exception as e:
        db.session.rollback()
        return jsonify({"status": "error", "message": str(e)}), 400

@app.route('/api/loyalty/<email>', methods=['GET'])
def get_loyalty(email):
    user_loyalty = Loyalty.query.filter_by(email=email).first()
    if user_loyalty:
        return jsonify({"email": email, "points": user_loyalty.points})
    return jsonify({"email": email, "points": 0})

@app.route('/api/menu', methods=['GET'])
def get_menu():
    items = Menu.query.all()
    menu_data = [{"name": i.name, "price": i.price, "category": i.category} for i in items]
    return jsonify(menu_data)

if __name__ == '__main__':
    with app.app_context():
        # Create database directory if it doesn't exist
        os.makedirs(os.path.join(app.instance_path), exist_ok=True)
        db.create_all()
        # Add sample menu items if empty
        if Menu.query.count() == 0:
            sample_items = [
                Menu(name="Truffle Pasta", price=25.0, category="Main Course"),
                Menu(name="Grilled Salmon", price=30.0, category="Main Course"),
                Menu(name="Caesar Salad", price=12.0, category="Starters"),
                Menu(name="Chocolate Lava Cake", price=10.0, category="Desserts")
            ]
            db.session.bulk_save_objects(sample_items)
            db.session.commit()
            print("Database initialized with sample data!")
    app.run(debug=True)
137 lines•5.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