Skip to content

Commit b236129

Browse files
Glucksbergobviyus
authored andcommitted
fix: trim legacy signature fallback, type fromChatType as union
1 parent 57566c5 commit b236129

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/telegram/bot/helpers.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ describe("normalizeForwardedContext", () => {
169169
expect(ctx?.from).toBe("My Channel (New Sig)");
170170
});
171171

172+
it("returns undefined signature when author_signature is blank", () => {
173+
const ctx = normalizeForwardedContext({
174+
forward_origin: {
175+
type: "channel",
176+
chat: { title: "Updates", id: -100333, type: "channel" },
177+
date: 860,
178+
author_signature: " ",
179+
message_id: 1,
180+
},
181+
// oxlint-disable-next-line typescript/no-explicit-any
182+
} as any);
183+
expect(ctx).not.toBeNull();
184+
expect(ctx?.fromSignature).toBeUndefined();
185+
expect(ctx?.from).toBe("Updates");
186+
});
187+
172188
it("handles forward_origin channel without author_signature", () => {
173189
const ctx = normalizeForwardedContext({
174190
forward_origin: {

src/telegram/bot/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ export function describeReplyTarget(msg: Message): TelegramReplyTarget | null {
253253
};
254254
}
255255

256+
export type TelegramChatType = "private" | "group" | "supergroup" | "channel";
257+
256258
export type TelegramForwardedContext = {
257259
from: string;
258260
date?: number;
@@ -262,7 +264,7 @@ export type TelegramForwardedContext = {
262264
fromTitle?: string;
263265
fromSignature?: string;
264266
/** Original chat type from forward_from_chat (e.g. "channel", "supergroup", "group"). */
265-
fromChatType?: string;
267+
fromChatType?: TelegramChatType;
266268
/** Original message ID in the source chat (channel forwards). */
267269
fromMessageId?: number;
268270
};
@@ -336,7 +338,7 @@ function buildForwardedContextFromChat(params: {
336338
}
337339
const signature = params.signature?.trim() || undefined;
338340
const from = signature ? `${display} (${signature})` : display;
339-
const chatType = params.chat.type?.trim() || undefined;
341+
const chatType = (params.chat.type?.trim() || undefined) as TelegramChatType | undefined;
340342
return {
341343
from,
342344
date: params.date,

0 commit comments

Comments
 (0)