diff --git a/plugin/index.ts b/plugin/index.ts index 3fcbc8b..f862ff4 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -27,6 +27,7 @@ const sessionDecision = new Map(); const sessionAllowed = new Map(); // Track if session was allowed to speak (true) or forced no-reply (false) const sessionInjected = new Set(); // Track which sessions have already injected the end marker const sessionChannelId = new Map(); // Track sessionKey -> channelId mapping +const sessionAccountId = new Map(); // Track sessionKey -> accountId mapping const MAX_SESSION_DECISIONS = 2000; const DECISION_TTL_MS = 5 * 60 * 1000; function buildEndMarkerInstruction(endSymbols: string[], isGroupChat: boolean): string { @@ -637,10 +638,13 @@ export default { } // Allowed to speak - record this session as allowed sessionAllowed.set(key, true); - // Also save channelId for this session + // Also save channelId and accountId for this session if (derived.channelId) { sessionChannelId.set(key, derived.channelId); } + if (accountId) { + sessionAccountId.set(key, accountId); + } } } @@ -836,6 +840,14 @@ export default { accountId = String(deliveryContext.accountId); } + // Fallback: get from session mapping + if (!channelId && key) { + channelId = sessionChannelId.get(key); + } + if (!accountId && key) { + accountId = sessionAccountId.get(key); + } + // Fallback: get content from event.message.content if (!content && (event as Record).message) { const msg = (event as Record).message as Record;