Spaces:
Running
Running
axeronis commited on
Commit ·
df6fb4c
1
Parent(s): 904d4db
fix: add voice preference check in webhook.py to override ALL voice triggers
Browse files- backend/app/api/webhook.py +22 -1
backend/app/api/webhook.py
CHANGED
|
@@ -1267,12 +1267,33 @@ async def process_ai_response_background(
|
|
| 1267 |
# AI can add [SEND_VOICE] tag when it detects persuasion/trust moment
|
| 1268 |
ai_wants_voice = "[SEND_VOICE]" in ai_response["text"]
|
| 1269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1270 |
# === SMART VOICE DETECTION (fallback if AI doesn't add tag) ===
|
| 1271 |
voice_trigger_reason = None
|
| 1272 |
user_text_lower = user_text.lower() if user_text else ""
|
| 1273 |
ai_text_lower = ai_response["text"].lower()
|
| 1274 |
|
| 1275 |
-
if not ai_wants_voice and tenant.voice_enabled:
|
| 1276 |
# 1. FIRST MESSAGE - greeting
|
| 1277 |
if is_first_message:
|
| 1278 |
voice_trigger_reason = "FIRST_MESSAGE"
|
|
|
|
| 1267 |
# AI can add [SEND_VOICE] tag when it detects persuasion/trust moment
|
| 1268 |
ai_wants_voice = "[SEND_VOICE]" in ai_response["text"]
|
| 1269 |
|
| 1270 |
+
# === CHECK IF USER REQUESTED NO VOICE IN HISTORY ===
|
| 1271 |
+
user_requested_no_voice = False
|
| 1272 |
+
no_voice_keywords = [
|
| 1273 |
+
'не присылай', 'не отправляй', 'не шли', 'не надо голос', 'не голос',
|
| 1274 |
+
'без голосов', 'только текст', 'пиши текст', 'текстом', 'зачем голос',
|
| 1275 |
+
'no voice', 'text only', 'хватит голос', 'голосовые не нужны'
|
| 1276 |
+
]
|
| 1277 |
+
for msg in conversation_history:
|
| 1278 |
+
if getattr(msg, 'sender_type', None) == 'user':
|
| 1279 |
+
msg_text = getattr(msg, 'content', '') or ''
|
| 1280 |
+
if any(kw in msg_text.lower() for kw in no_voice_keywords):
|
| 1281 |
+
user_requested_no_voice = True
|
| 1282 |
+
logger.info(f"🔇 USER REQUESTED NO VOICE (webhook check): {msg_text[:50]}")
|
| 1283 |
+
break
|
| 1284 |
+
|
| 1285 |
+
# If user requested no voice, disable all voice triggers
|
| 1286 |
+
if user_requested_no_voice:
|
| 1287 |
+
ai_wants_voice = False
|
| 1288 |
+
respond_with_voice = False
|
| 1289 |
+
logger.info("🔇 Voice DISABLED because user requested no voice messages")
|
| 1290 |
+
|
| 1291 |
# === SMART VOICE DETECTION (fallback if AI doesn't add tag) ===
|
| 1292 |
voice_trigger_reason = None
|
| 1293 |
user_text_lower = user_text.lower() if user_text else ""
|
| 1294 |
ai_text_lower = ai_response["text"].lower()
|
| 1295 |
|
| 1296 |
+
if not ai_wants_voice and tenant.voice_enabled and not user_requested_no_voice:
|
| 1297 |
# 1. FIRST MESSAGE - greeting
|
| 1298 |
if is_first_message:
|
| 1299 |
voice_trigger_reason = "FIRST_MESSAGE"
|