feat: emit ttsDeliveryStatus SSE diagnostics

Made-with: Cursor
This commit is contained in:
patrick-motsch 2026-02-26 09:46:05 +01:00
parent 02002f3576
commit cd2fffc651

View file

@ -848,6 +848,12 @@ class TeamsbotService:
# 4a: Voice response (TTS -> Audio to bot)
if sendVoice:
try:
await _emitSessionEvent(sessionId, "ttsDeliveryStatus", {
"status": "requested",
"hasWebSocket": websocket is not None,
"message": "TTS generation requested",
"timestamp": getIsoTimestamp(),
})
logger.info(
f"Session {sessionId}: TTS requested (websocket_available={websocket is not None})"
)
@ -877,12 +883,30 @@ class TeamsbotService:
},
}))
logger.info(f"Session {sessionId}: TTS audio dispatched to bot")
await _emitSessionEvent(sessionId, "ttsDeliveryStatus", {
"status": "dispatched",
"hasWebSocket": True,
"message": "TTS audio dispatched to bot",
"timestamp": getIsoTimestamp(),
})
else:
logger.warning(
f"Session {sessionId}: TTS audio generated but cannot be played (bot websocket unavailable, likely fallback mode)"
)
await _emitSessionEvent(sessionId, "ttsDeliveryStatus", {
"status": "unavailable",
"hasWebSocket": False,
"message": "TTS audio generated but bot websocket unavailable",
"timestamp": getIsoTimestamp(),
})
except Exception as ttsErr:
logger.warning(f"TTS failed for session {sessionId}: {ttsErr}")
await _emitSessionEvent(sessionId, "ttsDeliveryStatus", {
"status": "failed",
"hasWebSocket": websocket is not None,
"message": str(ttsErr),
"timestamp": getIsoTimestamp(),
})
if not sendChat:
sendChat = True # Fallback to chat if voice-only and TTS failed