Telegram: preserve topic IDs in restart notifications (#1807)
Co-authored-by: hsrvc <hsrvc@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,7 @@ export type AnnounceTarget = {
|
||||
channel: string;
|
||||
to: string;
|
||||
accountId?: string;
|
||||
threadId?: string; // Forum topic/thread ID
|
||||
};
|
||||
|
||||
export function resolveAnnounceTargetFromKey(sessionKey: string): AnnounceTarget | null {
|
||||
@@ -22,7 +23,22 @@ export function resolveAnnounceTargetFromKey(sessionKey: string): AnnounceTarget
|
||||
if (parts.length < 3) return null;
|
||||
const [channelRaw, kind, ...rest] = parts;
|
||||
if (kind !== "group" && kind !== "channel") return null;
|
||||
const id = rest.join(":").trim();
|
||||
|
||||
// Extract topic/thread ID from rest (supports both :topic: and :thread:)
|
||||
// Telegram uses :topic:, other platforms use :thread:
|
||||
let threadId: string | undefined;
|
||||
const restJoined = rest.join(":");
|
||||
const topicMatch = restJoined.match(/:topic:(\d+)$/);
|
||||
const threadMatch = restJoined.match(/:thread:(\d+)$/);
|
||||
const match = topicMatch || threadMatch;
|
||||
|
||||
if (match) {
|
||||
threadId = match[1]; // Keep as string to match AgentCommandOpts.threadId
|
||||
}
|
||||
|
||||
// Remove :topic:N or :thread:N suffix from ID for target
|
||||
const id = match ? restJoined.replace(/:(topic|thread):\d+$/, "") : restJoined.trim();
|
||||
|
||||
if (!id) return null;
|
||||
if (!channelRaw) return null;
|
||||
const normalizedChannel = normalizeAnyChannelId(channelRaw) ?? normalizeChatChannelId(channelRaw);
|
||||
@@ -37,7 +53,11 @@ export function resolveAnnounceTargetFromKey(sessionKey: string): AnnounceTarget
|
||||
const normalized = normalizedChannel
|
||||
? getChannelPlugin(normalizedChannel)?.messaging?.normalizeTarget?.(kindTarget)
|
||||
: undefined;
|
||||
return { channel, to: normalized ?? kindTarget };
|
||||
return {
|
||||
channel,
|
||||
to: normalized ?? kindTarget,
|
||||
threadId,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildAgentToAgentMessageContext(params: {
|
||||
|
||||
Reference in New Issue
Block a user