refactor: generalize channel type handling across various components

This commit is contained in:
Lauren ten Hoor
2026-02-10 09:56:17 +08:00
parent cb0f628772
commit 38ad3fe27f
8 changed files with 36 additions and 37 deletions

View File

@@ -12,10 +12,10 @@ import path from "node:path";
export type InteractionContext =
| { type: "via-agent"; agentId: string; agentName?: string }
| { type: "direct"; channel?: "telegram" | "whatsapp" | "cli" }
| { type: "direct"; channel?: string; chatId?: string }
| {
type: "group";
channel: "telegram" | "whatsapp";
channel: string;
groupId: string;
projectName?: string;
};
@@ -64,7 +64,7 @@ export async function detectContext(
return {
type: "group",
channel: messageChannel as "telegram" | "whatsapp",
channel: messageChannel,
groupId: actualGroupId,
projectName,
};
@@ -72,11 +72,12 @@ export async function detectContext(
}
// --- Direct (DM or CLI) ---
// Extract chat ID from sessionKey (e.g. "agent:devclaw:telegram:direct:657120585")
const chatId = sessionKey ? sessionKey.split(":").pop() : undefined;
return {
type: "direct",
channel: messageChannel
? (messageChannel as "telegram" | "whatsapp")
: "cli",
channel: messageChannel ?? "cli",
chatId,
};
}