diff --git a/backend/main.py b/backend/main.py index 27446e1..cf540e7 100644 --- a/backend/main.py +++ b/backend/main.py @@ -24,6 +24,16 @@ from datetime import timezone, timedelta logger = logging.getLogger(__name__) +# Configure logging for all modules +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' +) + +# Make sure WhatsApp module logs are visible +logging.getLogger('whatsapp').setLevel(logging.INFO) +logging.getLogger('whatsapp_templates').setLevel(logging.INFO) + import models import schemas import crud @@ -1929,5 +1939,62 @@ async def import_contacts( ) +# ============================================ +# WhatsApp Testing Endpoint (for debugging) +# ============================================ +@app.post("/api/test/whatsapp/send") +async def test_whatsapp_send( + phone: str, + template_key: str = "wedding_invitation_by_vered", + db: Session = Depends(get_db) +): + """ + Test endpoint to send a WhatsApp message. + + Example: + POST /api/test/whatsapp/send?phone=0504370045&template_key=wedding_invitation_by_vered + """ + try: + logger.info(f"[TEST] Attempting to send WhatsApp to {phone} using template {template_key}") + + service = get_whatsapp_service(db) + + # Test parameters + params = { + "contact_name": "דוד", + "event_date": "17/05", + "event_date_day": "17", + "venue": "אולם הגן", + "location": "ירושלים", + "reception_time": "18:30", + "ceremony_time": "19:00", + "dinner_time": "20:00", + "bride_name": "ורד", + "groom_name": "דביר", + "event_id": "test-event-id-12345" + } + + result = await service.send_by_template_key( + template_key=template_key, + to_phone=phone, + params=params + ) + + logger.info(f"[TEST] Message sent successfully: {result}") + + return { + "status": "sent", + "result": result, + "message": f"Test message sent to {phone} successfully" + } + + except Exception as e: + logger.error(f"[TEST] Failed to send test message: {str(e)}", exc_info=True) + raise HTTPException( + status_code=500, + detail=f"Failed to send test message: {str(e)}" + ) + + if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) \ No newline at end of file