Fix: Handle exceptions in warehouse search to prevent 'teknik sorun oluştu'
Browse files- Added try-catch block around get_warehouse_stock_smart_with_price call
- Added detailed error logging with traceback for debugging
- Now falls back to basic search if GPT-5 search fails
- Prevents app crashes when API key is missing or service is down
This fixes the "Teknik bir sorun oluştu" error users were experiencing.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
- __pycache__/app.cpython-312.pyc +0 -0
- __pycache__/intent_analyzer.cpython-312.pyc +0 -0
- __pycache__/media_queue_v2.cpython-312.pyc +0 -0
- __pycache__/prompts.cpython-312.pyc +0 -0
- __pycache__/smart_warehouse_with_price.cpython-312.pyc +0 -0
- __pycache__/store_notification.cpython-312.pyc +0 -0
- __pycache__/whatsapp_passive_profiler.cpython-312.pyc +0 -0
- __pycache__/whatsapp_renderer.cpython-312.pyc +0 -0
- app.py +32 -20
- check_twilio_logs.py +53 -0
__pycache__/app.cpython-312.pyc
ADDED
|
Binary file (68 kB). View file
|
|
|
__pycache__/intent_analyzer.cpython-312.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
__pycache__/media_queue_v2.cpython-312.pyc
ADDED
|
Binary file (11.3 kB). View file
|
|
|
__pycache__/prompts.cpython-312.pyc
ADDED
|
Binary file (8.29 kB). View file
|
|
|
__pycache__/smart_warehouse_with_price.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/smart_warehouse_with_price.cpython-312.pyc and b/__pycache__/smart_warehouse_with_price.cpython-312.pyc differ
|
|
|
__pycache__/store_notification.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/store_notification.cpython-312.pyc and b/__pycache__/store_notification.cpython-312.pyc differ
|
|
|
__pycache__/whatsapp_passive_profiler.cpython-312.pyc
ADDED
|
Binary file (17.7 kB). View file
|
|
|
__pycache__/whatsapp_renderer.cpython-312.pyc
ADDED
|
Binary file (9.28 kB). View file
|
|
|
app.py
CHANGED
|
@@ -111,26 +111,30 @@ def get_warehouse_stock(product_name):
|
|
| 111 |
"""B2B API'den mağaza stok bilgilerini çek - GPT-5 enhanced"""
|
| 112 |
# Try GPT-5 complete smart search (BF algorithm)
|
| 113 |
if USE_GPT5_SEARCH:
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
# Fallback to original search
|
| 136 |
try:
|
|
@@ -1211,6 +1215,10 @@ def process_whatsapp_message_with_memory(user_message, phone_number):
|
|
| 1211 |
|
| 1212 |
except Exception as e:
|
| 1213 |
print(f"❌ WhatsApp mesaj işleme hatası: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1214 |
return "Teknik bir sorun oluştu. Lütfen daha sonra tekrar deneyin."
|
| 1215 |
|
| 1216 |
def create_profile_context_message(profile_summary):
|
|
@@ -1417,6 +1425,10 @@ def process_whatsapp_message(user_message):
|
|
| 1417 |
|
| 1418 |
except Exception as e:
|
| 1419 |
print(f"❌ WhatsApp mesaj işleme hatası: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1420 |
return "Teknik bir sorun oluştu. Lütfen daha sonra tekrar deneyin."
|
| 1421 |
|
| 1422 |
# FastAPI uygulaması
|
|
|
|
| 111 |
"""B2B API'den mağaza stok bilgilerini çek - GPT-5 enhanced"""
|
| 112 |
# Try GPT-5 complete smart search (BF algorithm)
|
| 113 |
if USE_GPT5_SEARCH:
|
| 114 |
+
try:
|
| 115 |
+
gpt5_result = get_warehouse_stock_smart_with_price(product_name)
|
| 116 |
+
if gpt5_result and isinstance(gpt5_result, list):
|
| 117 |
+
# Return directly if it's already formatted strings
|
| 118 |
+
if all(isinstance(item, str) for item in gpt5_result):
|
| 119 |
+
return gpt5_result
|
| 120 |
+
# Format for WhatsApp if dict format
|
| 121 |
+
warehouse_info = []
|
| 122 |
+
for item in gpt5_result:
|
| 123 |
+
if isinstance(item, dict):
|
| 124 |
+
info = f"📦 {item.get('name', '')}"
|
| 125 |
+
if item.get('variant'):
|
| 126 |
+
info += f" ({item['variant']})"
|
| 127 |
+
if item.get('warehouses'):
|
| 128 |
+
info += f"\n📍 Mevcut: {', '.join(item['warehouses'])}"
|
| 129 |
+
if item.get('price'):
|
| 130 |
+
info += f"\n💰 {item['price']}"
|
| 131 |
+
warehouse_info.append(info)
|
| 132 |
+
else:
|
| 133 |
+
warehouse_info.append(str(item))
|
| 134 |
+
return warehouse_info if warehouse_info else None
|
| 135 |
+
except Exception as e:
|
| 136 |
+
logger.error(f"GPT-5 warehouse search error: {e}")
|
| 137 |
+
# Continue to fallback search
|
| 138 |
|
| 139 |
# Fallback to original search
|
| 140 |
try:
|
|
|
|
| 1215 |
|
| 1216 |
except Exception as e:
|
| 1217 |
print(f"❌ WhatsApp mesaj işleme hatası: {e}")
|
| 1218 |
+
import traceback
|
| 1219 |
+
traceback.print_exc()
|
| 1220 |
+
logger.error(f"Detailed error: {str(e)}")
|
| 1221 |
+
logger.error(f"Error type: {type(e).__name__}")
|
| 1222 |
return "Teknik bir sorun oluştu. Lütfen daha sonra tekrar deneyin."
|
| 1223 |
|
| 1224 |
def create_profile_context_message(profile_summary):
|
|
|
|
| 1425 |
|
| 1426 |
except Exception as e:
|
| 1427 |
print(f"❌ WhatsApp mesaj işleme hatası: {e}")
|
| 1428 |
+
import traceback
|
| 1429 |
+
traceback.print_exc()
|
| 1430 |
+
logger.error(f"Detailed error: {str(e)}")
|
| 1431 |
+
logger.error(f"Error type: {type(e).__name__}")
|
| 1432 |
return "Teknik bir sorun oluştu. Lütfen daha sonra tekrar deneyin."
|
| 1433 |
|
| 1434 |
# FastAPI uygulaması
|
check_twilio_logs.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Check recent Twilio messages"""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from twilio.rest import Client
|
| 6 |
+
from datetime import datetime, timedelta
|
| 7 |
+
|
| 8 |
+
# Twilio credentials
|
| 9 |
+
account_sid = os.getenv('TWILIO_ACCOUNT_SID')
|
| 10 |
+
auth_token = os.getenv('TWILIO_AUTH_TOKEN')
|
| 11 |
+
|
| 12 |
+
if not account_sid or not auth_token:
|
| 13 |
+
print("❌ Twilio credentials not found")
|
| 14 |
+
exit(1)
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
client = Client(account_sid, auth_token)
|
| 18 |
+
|
| 19 |
+
# Get messages from last 24 hours
|
| 20 |
+
yesterday = datetime.now() - timedelta(days=1)
|
| 21 |
+
|
| 22 |
+
print("📱 Son 24 saatteki WhatsApp mesajları:")
|
| 23 |
+
print("="*60)
|
| 24 |
+
|
| 25 |
+
messages = client.messages.list(
|
| 26 |
+
date_sent_after=yesterday,
|
| 27 |
+
limit=50
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
count = 0
|
| 31 |
+
for msg in messages:
|
| 32 |
+
if 'whatsapp' in msg.from_.lower() or 'whatsapp' in msg.to.lower():
|
| 33 |
+
count += 1
|
| 34 |
+
print(f"\n#{count}")
|
| 35 |
+
print(f"Tarih: {msg.date_sent}")
|
| 36 |
+
print(f"From: {msg.from_}")
|
| 37 |
+
print(f"To: {msg.to}")
|
| 38 |
+
print(f"Direction: {msg.direction}")
|
| 39 |
+
|
| 40 |
+
# Truncate long messages
|
| 41 |
+
body = msg.body if msg.body else "No body"
|
| 42 |
+
if len(body) > 200:
|
| 43 |
+
body = body[:200] + "..."
|
| 44 |
+
print(f"Message: {body}")
|
| 45 |
+
|
| 46 |
+
if count >= 20:
|
| 47 |
+
break
|
| 48 |
+
|
| 49 |
+
if count == 0:
|
| 50 |
+
print("No WhatsApp messages found in last 24 hours")
|
| 51 |
+
|
| 52 |
+
except Exception as e:
|
| 53 |
+
print(f"❌ Error: {e}")
|