fix(target): normalize actual destinations

Different target spellings can name the same actual destination.
Normalize channel, thread and topic identities for ownership checks
and per-route duplicate suppression.
This commit is contained in:
翅膀 committed 2026-10-23 23:23:22 +08:00
1 parent 0978c6c310
commit ceb906d479
1 file changed
+17
+17
View File
@@ -16,3 +16,20 @@ export function getDriver(target: RouteTarget): PlatformDriver {
if (!driver) throw new Error(`No driver for platform "${platform}"`);
return driver;
}
/**
* Where a target's messages actually go: two targets naming the same place
* (a Discord thread given alone, or with its parent channel) are one
* destination, and get one copy of each message.
*/
export function destinationOf(target: RouteTarget): string {
const platform = target.platform ?? "discord";
if (platform === "telegram") {
// Read as the driver sends it (a number): `01` and `1` are one topic.
const topic = target.topicId ?? "";
const id = topic && Number.isFinite(Number(topic)) ? String(Number(topic)) : topic;
return `telegram:${target.chatId ?? ""}/${id}`;
}
if (platform === "feishu") return `feishu:${target.chatId ?? ""}`;
return `discord:${target.threadId || target.channelId || ""}`;
}