fix: trim legacy signature fallback, type fromChatType as union

This commit is contained in:
Glucksberg
2026-02-04 03:22:39 +00:00
committed by Ayaan Zaidi
parent 57566c5e4d
commit b2361292e7
2 changed files with 20 additions and 2 deletions

View File

@@ -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: {

View File

@@ -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,