#!/usr/bin/env python3 """Check recent Twilio messages""" import os from twilio.rest import Client from datetime import datetime, timedelta # Twilio credentials account_sid = os.getenv('TWILIO_ACCOUNT_SID') auth_token = os.getenv('TWILIO_AUTH_TOKEN') if not account_sid or not auth_token: print("❌ Twilio credentials not found") exit(1) try: client = Client(account_sid, auth_token) # Get messages from last 24 hours yesterday = datetime.now() - timedelta(days=1) print("📱 Son 24 saatteki WhatsApp mesajları:") print("="*60) messages = client.messages.list( date_sent_after=yesterday, limit=50 ) count = 0 for msg in messages: if 'whatsapp' in msg.from_.lower() or 'whatsapp' in msg.to.lower(): count += 1 print(f"\n#{count}") print(f"Tarih: {msg.date_sent}") print(f"From: {msg.from_}") print(f"To: {msg.to}") print(f"Direction: {msg.direction}") # Truncate long messages body = msg.body if msg.body else "No body" if len(body) > 200: body = body[:200] + "..." print(f"Message: {body}") if count >= 20: break if count == 0: print("No WhatsApp messages found in last 24 hours") except Exception as e: print(f"❌ Error: {e}")