File size: 1,443 Bytes
2b14554 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#!/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}") |