diff --git a/src/telegram/bot/helpers.test.ts b/src/telegram/bot/helpers.test.ts index ebc774b92..526d2ec3a 100644 --- a/src/telegram/bot/helpers.test.ts +++ b/src/telegram/bot/helpers.test.ts @@ -169,6 +169,22 @@ describe("normalizeForwardedContext", () => { expect(ctx?.from).toBe("My Channel (New Sig)"); }); + it("returns undefined signature when author_signature is blank", () => { + const ctx = normalizeForwardedContext({ + forward_origin: { + type: "channel", + chat: { title: "Updates", id: -100333, type: "channel" }, + date: 860, + author_signature: " ", + message_id: 1, + }, + // oxlint-disable-next-line typescript/no-explicit-any + } as any); + expect(ctx).not.toBeNull(); + expect(ctx?.fromSignature).toBeUndefined(); + expect(ctx?.from).toBe("Updates"); + }); + it("handles forward_origin channel without author_signature", () => { const ctx = normalizeForwardedContext({ forward_origin: { diff --git a/src/telegram/bot/helpers.ts b/src/telegram/bot/helpers.ts index af2682ada..4b46db1cc 100644 --- a/src/telegram/bot/helpers.ts +++ b/src/telegram/bot/helpers.ts @@ -253,6 +253,8 @@ export function describeReplyTarget(msg: Message): TelegramReplyTarget | null { }; } +export type TelegramChatType = "private" | "group" | "supergroup" | "channel"; + export type TelegramForwardedContext = { from: string; date?: number; @@ -262,7 +264,7 @@ export type TelegramForwardedContext = { fromTitle?: string; fromSignature?: string; /** Original chat type from forward_from_chat (e.g. "channel", "supergroup", "group"). */ - fromChatType?: string; + fromChatType?: TelegramChatType; /** Original message ID in the source chat (channel forwards). */ fromMessageId?: number; }; @@ -336,7 +338,7 @@ function buildForwardedContextFromChat(params: { } const signature = params.signature?.trim() || undefined; const from = signature ? `${display} (${signature})` : display; - const chatType = params.chat.type?.trim() || undefined; + const chatType = (params.chat.type?.trim() || undefined) as TelegramChatType | undefined; return { from, date: params.date,