SamiKoen commited on
Commit
d20cc0a
·
verified ·
1 Parent(s): 94f8fba

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +4 -19
  2. whatsapp_features.py +63 -0
app.py CHANGED
@@ -7,9 +7,8 @@ from fastapi import FastAPI, Request
7
  from twilio.rest import Client
8
  from twilio.twiml.messaging_response import MessagingResponse
9
 
10
- # Yeni modüller - Enhanced Features
11
  from prompts import get_prompt_content_only
12
- import whatsapp_features # Global değişkenler için module import
13
  from whatsapp_renderer import extract_product_info_whatsapp
14
  from whatsapp_passive_profiler import (
15
  analyze_user_message, get_user_profile_summary, get_personalized_recommendations
@@ -209,9 +208,8 @@ try:
209
  print(f" Marlin ürünü: {marlin_count}")
210
  print(f" Products listesi: {len(products)} ürün")
211
 
212
- # Enhanced features başlat
213
- whatsapp_features.initialize_whatsapp_features(products)
214
- print("✅ WhatsApp enhanced features başlatıldı")
215
 
216
  if marlin_count == 0:
217
  print("❌ XML'de hiç Marlin ürünü bulunamadı!")
@@ -358,20 +356,7 @@ def process_whatsapp_message_with_memory(user_message, phone_number):
358
  custom_response = create_personalized_response(personalized, profile_summary)
359
  return extract_product_info_whatsapp(custom_response)
360
 
361
- # Enhanced features kontrolü - önce bunları kontrol et
362
- comparison_result = whatsapp_features.handle_whatsapp_comparison_request(user_message)
363
- if comparison_result:
364
- return extract_product_info_whatsapp(comparison_result)
365
-
366
- # Kategori+Bütçe kombinasyonu önce kontrol edilsin
367
- category_result = whatsapp_features.handle_whatsapp_category_request(user_message, phone_number)
368
- if category_result:
369
- return extract_product_info_whatsapp(category_result)
370
-
371
- # Sadece bütçe kontrolü
372
- budget_result = whatsapp_features.handle_whatsapp_budget_request(user_message)
373
- if budget_result:
374
- return extract_product_info_whatsapp(budget_result)
375
 
376
  # Sohbet geçmişi ile sistem mesajlarını oluştur
377
  messages = build_context_messages(phone_number, user_message)
 
7
  from twilio.rest import Client
8
  from twilio.twiml.messaging_response import MessagingResponse
9
 
10
+ # Yeni modüller - Basit sistem
11
  from prompts import get_prompt_content_only
 
12
  from whatsapp_renderer import extract_product_info_whatsapp
13
  from whatsapp_passive_profiler import (
14
  analyze_user_message, get_user_profile_summary, get_personalized_recommendations
 
208
  print(f" Marlin ürünü: {marlin_count}")
209
  print(f" Products listesi: {len(products)} ürün")
210
 
211
+ # Enhanced features kaldırıldı - GPT-4 doğal dil anlama kullanacak
212
+ print("✅ Basit sistem aktif - GPT-4 doğal dil anlama")
 
213
 
214
  if marlin_count == 0:
215
  print("❌ XML'de hiç Marlin ürünü bulunamadı!")
 
356
  custom_response = create_personalized_response(personalized, profile_summary)
357
  return extract_product_info_whatsapp(custom_response)
358
 
359
+ # Enhanced features kaldırıldı - GPT-4 doğal dil anlama kullanacak
 
 
 
 
 
 
 
 
 
 
 
 
 
360
 
361
  # Sohbet geçmişi ile sistem mesajlarını oluştur
362
  messages = build_context_messages(phone_number, user_message)
whatsapp_features.py CHANGED
@@ -263,6 +263,69 @@ def handle_whatsapp_comparison_request(user_message):
263
  print(f"WhatsApp Comparison error: {e}")
264
  return None
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  def handle_whatsapp_budget_request(user_message):
267
  """WhatsApp bütçe talebini işle"""
268
  try:
 
263
  print(f"WhatsApp Comparison error: {e}")
264
  return None
265
 
266
+ def handle_whatsapp_price_query(user_message):
267
+ """WhatsApp fiyat sorgusu - 'ne kadar', 'fiyat', 'kaç para' gibi"""
268
+ try:
269
+ user_lower = user_message.lower()
270
+
271
+ # Fiyat sorgusu anahtar kelimeleri
272
+ price_query_keywords = ["ne kadar", "fiyat", "kaç para", "fiyatı", "kaça", "para"]
273
+ if not any(keyword in user_lower for keyword in price_query_keywords):
274
+ return None
275
+
276
+ # Ürün adı tespit et
277
+ product_keywords = ["madone", "émonda", "domane", "marlin", "fuel", "powerfly", "fx", "checkpoint", "procaliber", "supercaliber", "ds", "verve", "rail"]
278
+ found_product = None
279
+
280
+ for keyword in product_keywords:
281
+ if keyword in user_lower:
282
+ found_product = keyword
283
+ break
284
+
285
+ if found_product and whatsapp_budget_recommendations:
286
+ # Ürünü products listesinde ara
287
+ matching_products = []
288
+ for product in whatsapp_budget_recommendations.products:
289
+ if product[1][0] == "stokta" and found_product in product[2].lower():
290
+ matching_products.append(product)
291
+
292
+ if matching_products:
293
+ # İlk ürünü al (en temel model)
294
+ main_product = matching_products[0]
295
+ name, item_info, full_name = main_product
296
+ price = item_info[1] if len(item_info) > 1 else "Fiyat yok"
297
+
298
+ try:
299
+ price_float = float(price)
300
+ price_formatted = f"{price_float:,.0f}"
301
+ except:
302
+ price_formatted = price
303
+
304
+ # Aynı serinin diğer modellerini bul
305
+ series_products = matching_products[:3] # İlk 3 model
306
+
307
+ response = f"🚲 **{found_product.upper()} SERİSİ FİYATLARI**\\n\\n"
308
+
309
+ for i, product in enumerate(series_products, 1):
310
+ name, item_info, full_name = product
311
+ price = item_info[1] if len(item_info) > 1 else "Fiyat yok"
312
+
313
+ try:
314
+ price_float = float(price)
315
+ price_formatted = f"{price_float:,.0f}"
316
+ except:
317
+ price_formatted = price
318
+
319
+ response += f"**{i}. {full_name}**\\n"
320
+ response += f"💰 Fiyat: {price_formatted} TL\\n\\n"
321
+
322
+ return response
323
+
324
+ return None
325
+ except Exception as e:
326
+ print(f"WhatsApp Price Query error: {e}")
327
+ return None
328
+
329
  def handle_whatsapp_budget_request(user_message):
330
  """WhatsApp bütçe talebini işle"""
331
  try: