Spaces:
Running

axeronis commited on
Commit
22169b1
·
1 Parent(s): bc1413f

feat: auto-send voice for first greeting message + add voice decision logging

Browse files
Files changed (1) hide show
  1. backend/app/api/webhook.py +12 -0
backend/app/api/webhook.py CHANGED
@@ -1259,14 +1259,26 @@ async def process_ai_response_background(
1259
 
1260
  try:
1261
  if channel == 'telegram':
 
 
 
 
1262
  # Check if AI wants to send voice (proactive) or user sent voice (reactive)
1263
  # AI can add [SEND_VOICE] tag when it detects persuasion/trust moment
1264
  ai_wants_voice = "[SEND_VOICE]" in ai_response["text"]
 
 
 
 
 
 
1265
  should_send_voice = (
1266
  tenant.voice_enabled and
1267
  (respond_with_voice or ai_wants_voice)
1268
  )
1269
 
 
 
1270
  # Clean up voice tag from response text
1271
  if ai_wants_voice:
1272
  ai_response["text"] = ai_response["text"].replace("[SEND_VOICE]", "").strip()
 
1259
 
1260
  try:
1261
  if channel == 'telegram':
1262
+ # Count AI messages to detect first message
1263
+ ai_msg_count = len([m for m in conversation_history if getattr(m, 'sender_type', None) == 'ai'])
1264
+ is_first_message = ai_msg_count == 0
1265
+
1266
  # Check if AI wants to send voice (proactive) or user sent voice (reactive)
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
+ # AUTO-VOICE for first message (greeting) if voice enabled
1271
+ if is_first_message and tenant.voice_enabled and not ai_wants_voice:
1272
+ logger.info("🎙️ Auto-adding voice for FIRST MESSAGE greeting")
1273
+ ai_wants_voice = True
1274
+
1275
  should_send_voice = (
1276
  tenant.voice_enabled and
1277
  (respond_with_voice or ai_wants_voice)
1278
  )
1279
 
1280
+ logger.info(f"🔊 Voice decision: enabled={tenant.voice_enabled}, first_msg={is_first_message}, ai_wants={ai_wants_voice}, respond_with={respond_with_voice}, RESULT={should_send_voice}")
1281
+
1282
  # Clean up voice tag from response text
1283
  if ai_wants_voice:
1284
  ai_response["text"] = ai_response["text"].replace("[SEND_VOICE]", "").strip()