* fix(acp): normalize unicode flags and Telegram topic binding * feat(telegram/acp): restore topic-bound ACP and session bindings * fix(acpx): clarify permission-denied guidance * feat(telegram/acp): pin spawn bind notice in topics * docs(telegram): document ACP topic thread binding behavior * refactor(reply): share Telegram conversation-id resolver * fix(telegram/acp): preserve bound session routing semantics * fix(telegram): respect binding persistence and expiry reporting * refactor(telegram): simplify binding lifecycle persistence * fix(telegram): bind acp spawns in direct messages * fix: document telegram ACP topic binding changelog (#36683) (thanks @huntharo) --------- Co-authored-by: Onur <2453968+osolmaz@users.noreply.github.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { parseTelegramTarget } from "../../telegram/targets.js";
|
|
|
|
type TelegramConversationParams = {
|
|
ctx: {
|
|
MessageThreadId?: string | number | null;
|
|
OriginatingTo?: string;
|
|
To?: string;
|
|
};
|
|
command: {
|
|
to?: string;
|
|
};
|
|
};
|
|
|
|
export function resolveTelegramConversationId(
|
|
params: TelegramConversationParams,
|
|
): string | undefined {
|
|
const rawThreadId =
|
|
params.ctx.MessageThreadId != null ? String(params.ctx.MessageThreadId).trim() : "";
|
|
const threadId = rawThreadId || undefined;
|
|
const toCandidates = [
|
|
typeof params.ctx.OriginatingTo === "string" ? params.ctx.OriginatingTo : "",
|
|
typeof params.command.to === "string" ? params.command.to : "",
|
|
typeof params.ctx.To === "string" ? params.ctx.To : "",
|
|
]
|
|
.map((value) => value.trim())
|
|
.filter(Boolean);
|
|
const chatId = toCandidates
|
|
.map((candidate) => parseTelegramTarget(candidate).chatId.trim())
|
|
.find((candidate) => candidate.length > 0);
|
|
if (!chatId) {
|
|
return undefined;
|
|
}
|
|
if (threadId) {
|
|
return `${chatId}:topic:${threadId}`;
|
|
}
|
|
// Non-topic groups should not become globally focused conversations.
|
|
if (chatId.startsWith("-")) {
|
|
return undefined;
|
|
}
|
|
return chatId;
|
|
}
|