fix: safe access to botAccountEmail in _isBotSpeaker - was crashing WebSocket handler on first transcript

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
patrick-motsch 2026-02-17 23:54:18 +01:00
parent a27307263f
commit 070e3cbd96

View file

@ -231,6 +231,15 @@ class TeamsbotService:
if self._sessionContext:
logger.info(f"Session {sessionId}: Session context ready ({len(self._sessionContext)} chars)")
# Resolve system bot email for speaker detection (prevents bot from triggering AI on own speech)
try:
systemBot = interface.getActiveSystemBot(self.mandateId)
self._botAccountEmail = systemBot.get("email") if systemBot else None
if self._botAccountEmail:
logger.info(f"Session {sessionId}: Bot account email resolved: {self._botAccountEmail}")
except Exception:
self._botAccountEmail = None
logger.info(f"[WS-DEBUG] WebSocket handler started for session {sessionId}")
try:
@ -500,8 +509,9 @@ class TeamsbotService:
return True
# Match against bot account email prefix (e.g. "nyla.larsson" from "nyla.larsson@poweron.swiss")
if self.config.botAccountEmail:
emailPrefix = self.config.botAccountEmail.split("@")[0].lower().replace(".", " ")
botAccountEmail = getattr(self, '_botAccountEmail', None) or getattr(self.config, 'botAccountEmail', None)
if botAccountEmail:
emailPrefix = botAccountEmail.split("@")[0].lower().replace(".", " ")
if emailPrefix in speakerLower:
return True