suggest_slots(conversation_id, profile_name) - modules/integrations/calendar_integration.py:16Current Implementation: Mocked slot generation with real calendar API fallback
def suggest_slots(conversation_id, profile_name):
"""Suggest available slots based on real calendar availability"""
try:
from calendar_integration import get_available_slots
# Try real calendar integration first
available_slots = get_available_slots(...)
return slots[:15 if profile_name == "premium" else 6]
except Exception as e:
# Fallback to mock implementation
return suggest_slots_mock(conversation_id, profile_name)
Status: Mocked with real API integration framework ready
book_slot(conversation_id, start_time, end_time, title, description) - modules/integrations/calendar_integration.py:175Current Implementation: Mocked booking with dashboard integration
def book_slot(conversation_id, start_time, end_time, title, description):
"""Book a slot in Google Calendar and send to dashboard"""
print(f"📅 Booking slot: {start_time} - {end_time}")
# Create readable event ID
event_id = f"dummy_event_{conversation_id}_{start_dt.strftime('%Y%m%d_%H%M')}"
# Send to dashboard (real integration)
send_lesson_to_dashboard(lesson_data)
return {"id": event_id, "start": start_time, "end": end_time}
Status: Mocked with real dashboard integration
modules/core/config.py:189Current Implementation: Production-ready configuration system
PLANNING_PROFILES = {
"new": {
"duration_minutes": 60,
"earliest_hour": 10,
"latest_hour": 20,
"min_lead_minutes": 720,
"days_ahead": 10,
"exclude_weekends": True
},
"existing": {
"duration_minutes": 60,
"earliest_hour": 9,
"latest_hour": 21,
"min_lead_minutes": 360,
"days_ahead": 14,
"exclude_weekends": True
},
"weekend": {
"duration_minutes": 60,
"earliest_hour": 10,
"latest_hour": 18,
"min_lead_minutes": 180,
"days_ahead": 7,
"exclude_weekends": False,
"allowed_weekdays": [5, 6]
},
"premium": {
"duration_minutes": 90,
"earliest_hour": 8,
"latest_hour": 22,
"min_lead_minutes": 240,
"days_ahead": 21,
"exclude_weekends": False
}
}
Status: ✅ IMPLEMENTED - Real planning configuration system
detect_segment(contact_id) - modules/utils/mapping.py:283Current Implementation: Production-ready segment detection logic
def detect_segment(contact_id):
"""Detect segment based on contact attributes and history"""
contact_attrs = get_contact_attrs(contact_id)
# Check if segment is already set
existing_segment = contact_attrs.get("segment")
if existing_segment:
return existing_segment
# 1. Weekend segment (whitelist check)
if contact_attrs.get("weekend_whitelisted"):
segment = "weekend"
# 2. Returning broadcast (begin school year list)
elif contact_attrs.get("returning_broadcast"):
segment = "returning_broadcast"
# 3. Existing customer - check multiple indicators
elif (contact_attrs.get("customer_since") or
contact_attrs.get("has_paid_lesson") or
contact_attrs.get("has_completed_intake") or
contact_attrs.get("intake_completed") or
contact_attrs.get("trial_lesson_completed") or
contact_attrs.get("lesson_booked") or
contact_attrs.get("customer_status") == "active"):
segment = "existing"
# 4. Default to new
else:
segment = "new"
# Cache segment for future calls
set_contact_attrs(contact_id, {"segment": segment})
return segment
Status: ✅ IMPLEMENTED - Real customer segmentation
create_payment_link(segment, minutes, order_id, conversation_id, student_name, service, audience, program) - main.py:219 → modules/handlers/payment.py:66Current Implementation: Placeholder with full implementation in main.py
# In main.py (full implementation)
def create_payment_link(segment, minutes, order_id, conversation_id, student_name, service, audience, program):
from modules.handlers.payment import create_payment_link as _create_payment_link
return _create_payment_link(segment, minutes, order_id, conversation_id, student_name, service, audience, program)
# In modules/handlers/payment.py (placeholder)
def create_payment_link(segment, minutes, order_id, conversation_id, student_name, service, audience, program):
payment_link = "https://example.com/payment" # Placeholder
return payment_link
Status: Partially implemented
verify_stripe_webhook(payload, signature) - main.py:223 → modules/handlers/payment.py:78Current Implementation: Production-ready HMAC verification
def verify_stripe_webhook(payload, signature):
"""Verify Stripe webhook HMAC using configured secret."""
if not STRIPE_WEBHOOK_SECRET:
return True
try:
expected = hmac.new(
STRIPE_WEBHOOK_SECRET.encode(),
payload,
hashlib.sha256
).hexdigest()
return hmac.compare_digest(signature, expected)
except Exception:
return False
Status: ✅ FULLY IMPLEMENTED - Real Stripe webhook verification
handle_payment_success(event) - modules/handlers/payment.py:28Current Implementation: Production-ready payment processing
def handle_payment_success(event):
"""Handle payment success - moved from main.py"""
print(f"💳 Processing payment success event")
# Extract payment data
payment_intent = event.get("data", {}).get("object", {})
metadata = payment_intent.get("metadata", {})
conversation_id = metadata.get("conversation_id")
contact_id = metadata.get("contact_id")
# Update conversation and contact attributes
set_conv_attrs(conversation_id, {
"payment_completed": True,
"payment_intent_id": payment_intent.get("id"),
"payment_amount": payment_intent.get("amount"),
"payment_currency": payment_intent.get("currency")
})
set_contact_attrs(contact_id, {
"has_paid_lesson": True,
"has_completed_intake": True,
"lesson_booked": True,
"customer_since": datetime.now(TZ).isoformat()
})
# Send confirmation message
send_text_with_duplicate_check(conversation_id, t("payment_success_message", "nl"))
Status: ✅ FULLY IMPLEMENTED - Real Stripe webhook processing
STANDARD_PRICE_ID_60 = os.getenv("STANDARD_PRICE_ID_60")
STANDARD_PRICE_ID_90 = os.getenv("STANDARD_PRICE_ID_90")
WEEKEND_PRICE_ID_60 = os.getenv("WEEKEND_PRICE_ID_60")
WEEKEND_PRICE_ID_90 = os.getenv("WEEKEND_PRICE_ID_90")
Status: ✅ CONFIGURED - Real Stripe product configuration
GCAL_SERVICE_ACCOUNT_JSON = os.getenv("GCAL_SERVICE_ACCOUNT_JSON")
GCAL_CALENDAR_ID = os.getenv("GCAL_CALENDAR_ID", "primary")
Needs: Real Google Calendar setup
Google Calendar API Setup
Stripe API Setup ✅ COMPLETED
Replace suggest_slots()
Replace create_payment_link()
Replace book_slot()
Replace handle_payment_success() ✅ COMPLETED
Unit Tests
Integration Tests
Unit Tests
Integration Tests
Google Cloud Platform
Stripe ✅ COMPLETED
# Google Calendar
GCAL_SERVICE_ACCOUNT_JSON="path/to/service-account.json"
GCAL_CALENDAR_ID="primary"
# Stripe ✅ CONFIGURED
STRIPE_WEBHOOK_SECRET="whsec_..."
STANDARD_PRICE_ID_60="price_..."
STANDARD_PRICE_ID_90="price_..."
WEEKEND_PRICE_ID_60="price_..."
WEEKEND_PRICE_ID_90="price_..."
Last Updated: December 2024
Status: Payment Integration Complete, Calendar Integration Pending