fix: trim legacy signature fallback, type fromChatType as union
parent
57566c5e4d
commit
b2361292e7
|
|
@ -169,6 +169,22 @@ describe("normalizeForwardedContext", () => {
|
||||||
expect(ctx?.from).toBe("My Channel (New Sig)");
|
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", () => {
|
it("handles forward_origin channel without author_signature", () => {
|
||||||
const ctx = normalizeForwardedContext({
|
const ctx = normalizeForwardedContext({
|
||||||
forward_origin: {
|
forward_origin: {
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,8 @@ export function describeReplyTarget(msg: Message): TelegramReplyTarget | null {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TelegramChatType = "private" | "group" | "supergroup" | "channel";
|
||||||
|
|
||||||
export type TelegramForwardedContext = {
|
export type TelegramForwardedContext = {
|
||||||
from: string;
|
from: string;
|
||||||
date?: number;
|
date?: number;
|
||||||
|
|
@ -262,7 +264,7 @@ export type TelegramForwardedContext = {
|
||||||
fromTitle?: string;
|
fromTitle?: string;
|
||||||
fromSignature?: string;
|
fromSignature?: string;
|
||||||
/** Original chat type from forward_from_chat (e.g. "channel", "supergroup", "group"). */
|
/** 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). */
|
/** Original message ID in the source chat (channel forwards). */
|
||||||
fromMessageId?: number;
|
fromMessageId?: number;
|
||||||
};
|
};
|
||||||
|
|
@ -336,7 +338,7 @@ function buildForwardedContextFromChat(params: {
|
||||||
}
|
}
|
||||||
const signature = params.signature?.trim() || undefined;
|
const signature = params.signature?.trim() || undefined;
|
||||||
const from = signature ? `${display} (${signature})` : display;
|
const from = signature ? `${display} (${signature})` : display;
|
||||||
const chatType = params.chat.type?.trim() || undefined;
|
const chatType = (params.chat.type?.trim() || undefined) as TelegramChatType | undefined;
|
||||||
return {
|
return {
|
||||||
from,
|
from,
|
||||||
date: params.date,
|
date: params.date,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue