Fix sending messages
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
8dd7d9bf9b
commit
18de92aa3a
@ -24,6 +24,16 @@ from datetime import timezone, timedelta
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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 models
|
||||||
import schemas
|
import schemas
|
||||||
import crud
|
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__":
|
if __name__ == "__main__":
|
||||||
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
||||||
Loading…
x
Reference in New Issue
Block a user