From 070e3cbd96f5efc5bcbac8a743a98535b306931c Mon Sep 17 00:00:00 2001 From: patrick-motsch Date: Tue, 17 Feb 2026 23:54:18 +0100 Subject: [PATCH] fix: safe access to botAccountEmail in _isBotSpeaker - was crashing WebSocket handler on first transcript Co-authored-by: Cursor --- modules/features/teamsbot/service.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/features/teamsbot/service.py b/modules/features/teamsbot/service.py index e1c2745a..6f54927b 100644 --- a/modules/features/teamsbot/service.py +++ b/modules/features/teamsbot/service.py @@ -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