From b99eb4c9f3e249239f2cd3a019be3ab100e77c59 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 10 Jan 2026 16:47:28 +0100 Subject: [PATCH] fix(auto-reply): apply native commands to target session --- src/auto-reply/reply/session.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/auto-reply/reply/session.ts b/src/auto-reply/reply/session.ts index 1f11cef14..e53cea245 100644 --- a/src/auto-reply/reply/session.ts +++ b/src/auto-reply/reply/session.ts @@ -90,10 +90,20 @@ export async function initSessionState(params: { commandAuthorized: boolean; }): Promise { const { ctx, cfg, commandAuthorized } = params; + // Native slash commands (Telegram/Discord/Slack) are delivered on a separate + // "slash session" key, but should mutate the target chat session. + const targetSessionKey = + ctx.CommandSource === "native" + ? ctx.CommandTargetSessionKey?.trim() + : undefined; + const sessionCtxForState = + targetSessionKey && targetSessionKey !== ctx.SessionKey + ? { ...ctx, SessionKey: targetSessionKey } + : ctx; const sessionCfg = cfg.session; const mainKey = normalizeMainKey(sessionCfg?.mainKey); const agentId = resolveSessionAgentId({ - sessionKey: ctx.SessionKey, + sessionKey: sessionCtxForState.SessionKey, config: cfg, }); const resetTriggers = sessionCfg?.resetTriggers?.length @@ -122,7 +132,7 @@ export async function initSessionState(params: { let persistedModelOverride: string | undefined; let persistedProviderOverride: string | undefined; - const groupResolution = resolveGroupSessionKey(ctx) ?? undefined; + const groupResolution = resolveGroupSessionKey(sessionCtxForState) ?? undefined; const isGroup = ctx.ChatType?.trim().toLowerCase() === "group" || Boolean(groupResolution); const triggerBodyNormalized = stripStructuralPrefixes(ctx.Body ?? "") @@ -161,7 +171,7 @@ export async function initSessionState(params: { } } - sessionKey = resolveSessionKey(sessionScope, ctx, mainKey); + sessionKey = resolveSessionKey(sessionScope, sessionCtxForState, mainKey); if (groupResolution?.legacyKey && groupResolution.legacyKey !== sessionKey) { const legacyEntry = sessionStore[groupResolution.legacyKey]; if (legacyEntry && !sessionStore[sessionKey]) {