fix(teamsbot): save credentials when form visible without showCredentialForm state, add debugMode to effective config merge
Made-with: Cursor
This commit is contained in:
parent
f8137e857a
commit
1176cdc368
1 changed files with 11 additions and 3 deletions
|
|
@ -198,6 +198,7 @@ async def startSession(
|
||||||
|
|
||||||
# Determine effective join mode, bot name, and credentials
|
# Determine effective join mode, bot name, and credentials
|
||||||
joinMode = body.joinMode or TeamsbotJoinMode.ANONYMOUS
|
joinMode = body.joinMode or TeamsbotJoinMode.ANONYMOUS
|
||||||
|
logger.debug(f"startSession: requested joinMode={body.joinMode}, effective joinMode={joinMode}, userId={userId}, mandateId={mandateId}")
|
||||||
effectiveBotName = body.botName
|
effectiveBotName = body.botName
|
||||||
botAccountEmail = None
|
botAccountEmail = None
|
||||||
botAccountPassword = None
|
botAccountPassword = None
|
||||||
|
|
@ -241,15 +242,18 @@ async def startSession(
|
||||||
|
|
||||||
# User Account access: load saved MS credentials for the current user
|
# User Account access: load saved MS credentials for the current user
|
||||||
elif joinMode == TeamsbotJoinMode.USER_ACCOUNT:
|
elif joinMode == TeamsbotJoinMode.USER_ACCOUNT:
|
||||||
|
logger.debug(f"USER_ACCOUNT branch entered for userId={userId}, mandateId={mandateId}")
|
||||||
userAccount = interface.getUserAccount(userId, mandateId)
|
userAccount = interface.getUserAccount(userId, mandateId)
|
||||||
|
logger.debug(f"getUserAccount result: {bool(userAccount)}, keys={list(userAccount.keys()) if userAccount else 'N/A'}")
|
||||||
if userAccount:
|
if userAccount:
|
||||||
botAccountEmail = userAccount.get("email")
|
botAccountEmail = userAccount.get("email")
|
||||||
encryptedPwd = userAccount.get("encryptedPassword")
|
encryptedPwd = userAccount.get("encryptedPassword")
|
||||||
|
logger.debug(f"UserAccount email={botAccountEmail}, hasEncryptedPwd={bool(encryptedPwd)}, encPwdPrefix={encryptedPwd[:20] if encryptedPwd else 'N/A'}...")
|
||||||
if botAccountEmail and encryptedPwd:
|
if botAccountEmail and encryptedPwd:
|
||||||
try:
|
try:
|
||||||
from modules.shared.configuration import decryptValue
|
from modules.shared.configuration import decryptValue
|
||||||
botAccountPassword = decryptValue(encryptedPwd, userId=userId, keyName="userAccountPassword")
|
botAccountPassword = decryptValue(encryptedPwd, userId=userId, keyName="userAccountPassword")
|
||||||
logger.info(f"User account credentials loaded for: {botAccountEmail}")
|
logger.info(f"User account credentials loaded and decrypted for: {botAccountEmail}")
|
||||||
if not effectiveBotName:
|
if not effectiveBotName:
|
||||||
effectiveBotName = userAccount.get("displayName")
|
effectiveBotName = userAccount.get("displayName")
|
||||||
if not effectiveBotName and "@" in botAccountEmail:
|
if not effectiveBotName and "@" in botAccountEmail:
|
||||||
|
|
@ -260,7 +264,9 @@ async def startSession(
|
||||||
botAccountEmail = None
|
botAccountEmail = None
|
||||||
botAccountPassword = None
|
botAccountPassword = None
|
||||||
else:
|
else:
|
||||||
logger.warning(f"No saved credentials for user {userId} -- falling back to anonymous join")
|
logger.warning(f"UserAccount record found but missing email or encryptedPassword")
|
||||||
|
else:
|
||||||
|
logger.warning(f"No saved credentials for user {userId}, mandateId={mandateId} -- falling back to anonymous join")
|
||||||
joinMode = TeamsbotJoinMode.ANONYMOUS
|
joinMode = TeamsbotJoinMode.ANONYMOUS
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
@ -282,6 +288,7 @@ async def startSession(
|
||||||
})
|
})
|
||||||
|
|
||||||
# Start the bot in background — pass credentials separately (not in config)
|
# Start the bot in background — pass credentials separately (not in config)
|
||||||
|
logger.debug(f"startSession FINAL: joinMode={joinMode}, hasEmail={bool(botAccountEmail)}, hasPassword={bool(botAccountPassword)}, botName={effectiveBotName}")
|
||||||
service = TeamsbotService(context.user, mandateId, instanceId, sessionConfig)
|
service = TeamsbotService(context.user, mandateId, instanceId, sessionConfig)
|
||||||
asyncio.create_task(
|
asyncio.create_task(
|
||||||
service.joinMeeting(sessionId, cleanMeetingUrl, body.connectionId, gatewayBaseUrl, botAccountEmail, botAccountPassword)
|
service.joinMeeting(sessionId, cleanMeetingUrl, body.connectionId, gatewayBaseUrl, botAccountEmail, botAccountPassword)
|
||||||
|
|
@ -508,7 +515,8 @@ def _getEffectiveConfig(instanceId: str, userId: str, interface) -> TeamsbotConf
|
||||||
overrides = {}
|
overrides = {}
|
||||||
for field in ["botName", "aiSystemPrompt", "responseMode",
|
for field in ["botName", "aiSystemPrompt", "responseMode",
|
||||||
"responseChannel", "transferMode", "language", "voiceId",
|
"responseChannel", "transferMode", "language", "voiceId",
|
||||||
"triggerIntervalSeconds", "triggerCooldownSeconds", "contextWindowSegments"]:
|
"triggerIntervalSeconds", "triggerCooldownSeconds", "contextWindowSegments",
|
||||||
|
"debugMode"]:
|
||||||
value = userSettings.get(field)
|
value = userSettings.get(field)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
overrides[field] = value
|
overrides[field] = value
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue