Spaces:
Running
Running
axeronis commited on
Commit ·
d5ac7bd
1
Parent(s): 3ff107f
fix: user voice request bypasses frequency limit
Browse files- backend/app/api/webhook.py +10 -9
backend/app/api/webhook.py
CHANGED
|
@@ -1296,16 +1296,17 @@ async def process_ai_response_background(
|
|
| 1296 |
# FREQUENCY LIMIT: Only 1 voice per 5+ messages
|
| 1297 |
voice_allowed_by_frequency = recent_ai_voice_count < 1 or ai_msg_count % 5 == 0
|
| 1298 |
|
| 1299 |
-
|
| 1300 |
-
|
| 1301 |
-
|
| 1302 |
-
|
| 1303 |
-
|
| 1304 |
-
|
| 1305 |
-
|
| 1306 |
-
|
|
|
|
| 1307 |
# 1. FIRST MESSAGE - greeting (always voice for trust)
|
| 1308 |
-
|
| 1309 |
voice_trigger_reason = "FIRST_MESSAGE"
|
| 1310 |
ai_wants_voice = True
|
| 1311 |
|
|
|
|
| 1296 |
# FREQUENCY LIMIT: Only 1 voice per 5+ messages
|
| 1297 |
voice_allowed_by_frequency = recent_ai_voice_count < 1 or ai_msg_count % 5 == 0
|
| 1298 |
|
| 1299 |
+
# 0. USER EXPLICITLY REQUESTED VOICE - highest priority, bypasses frequency limit
|
| 1300 |
+
user_requested_voice = ai_response.get("user_requested_voice", False)
|
| 1301 |
+
if not ai_wants_voice and tenant.voice_enabled and not user_requested_no_voice and user_requested_voice:
|
| 1302 |
+
voice_trigger_reason = "USER_REQUESTED"
|
| 1303 |
+
ai_wants_voice = True
|
| 1304 |
+
logger.info("🎙️ Voice triggered: USER explicitly requested voice (bypasses frequency limit)")
|
| 1305 |
+
|
| 1306 |
+
# Smart triggers (subject to frequency limit)
|
| 1307 |
+
elif not ai_wants_voice and tenant.voice_enabled and not user_requested_no_voice and voice_allowed_by_frequency:
|
| 1308 |
# 1. FIRST MESSAGE - greeting (always voice for trust)
|
| 1309 |
+
if is_first_message:
|
| 1310 |
voice_trigger_reason = "FIRST_MESSAGE"
|
| 1311 |
ai_wants_voice = True
|
| 1312 |
|