fix(auto-reply): apply native commands to target session
This commit is contained in:
@@ -90,10 +90,20 @@ export async function initSessionState(params: {
|
|||||||
commandAuthorized: boolean;
|
commandAuthorized: boolean;
|
||||||
}): Promise<SessionInitResult> {
|
}): Promise<SessionInitResult> {
|
||||||
const { ctx, cfg, commandAuthorized } = params;
|
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 sessionCfg = cfg.session;
|
||||||
const mainKey = normalizeMainKey(sessionCfg?.mainKey);
|
const mainKey = normalizeMainKey(sessionCfg?.mainKey);
|
||||||
const agentId = resolveSessionAgentId({
|
const agentId = resolveSessionAgentId({
|
||||||
sessionKey: ctx.SessionKey,
|
sessionKey: sessionCtxForState.SessionKey,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
});
|
});
|
||||||
const resetTriggers = sessionCfg?.resetTriggers?.length
|
const resetTriggers = sessionCfg?.resetTriggers?.length
|
||||||
@@ -122,7 +132,7 @@ export async function initSessionState(params: {
|
|||||||
let persistedModelOverride: string | undefined;
|
let persistedModelOverride: string | undefined;
|
||||||
let persistedProviderOverride: string | undefined;
|
let persistedProviderOverride: string | undefined;
|
||||||
|
|
||||||
const groupResolution = resolveGroupSessionKey(ctx) ?? undefined;
|
const groupResolution = resolveGroupSessionKey(sessionCtxForState) ?? undefined;
|
||||||
const isGroup =
|
const isGroup =
|
||||||
ctx.ChatType?.trim().toLowerCase() === "group" || Boolean(groupResolution);
|
ctx.ChatType?.trim().toLowerCase() === "group" || Boolean(groupResolution);
|
||||||
const triggerBodyNormalized = stripStructuralPrefixes(ctx.Body ?? "")
|
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) {
|
if (groupResolution?.legacyKey && groupResolution.legacyKey !== sessionKey) {
|
||||||
const legacyEntry = sessionStore[groupResolution.legacyKey];
|
const legacyEntry = sessionStore[groupResolution.legacyKey];
|
||||||
if (legacyEntry && !sessionStore[sessionKey]) {
|
if (legacyEntry && !sessionStore[sessionKey]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user