File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -470,6 +470,28 @@ describe("sendMessageTelegram", () => {
470470 ) . rejects . toThrow ( / c o u l d n o t b e r e s o l v e d t o a n u m e r i c c h a t I D / i) ;
471471 } ) ;
472472
473+ it ( "sends bare group-prefixed numeric delivery targets without lookup" , async ( ) => {
474+ const sendMessage = vi . fn ( ) . mockResolvedValue ( {
475+ message_id : 1 ,
476+ chat : { id : "-100123" } ,
477+ } ) ;
478+ const getChat = vi . fn ( ) ;
479+ const api = { sendMessage, getChat } as unknown as {
480+ sendMessage : typeof sendMessage ;
481+ getChat : typeof getChat ;
482+ } ;
483+
484+ await sendMessageTelegram ( "group:-100123" , "hi" , {
485+ token : "tok" ,
486+ api,
487+ } ) ;
488+
489+ expect ( getChat ) . not . toHaveBeenCalled ( ) ;
490+ expect ( sendMessage ) . toHaveBeenCalledWith ( "-100123" , "hi" , {
491+ parse_mode : "HTML" ,
492+ } ) ;
493+ } ) ;
494+
473495 it ( "includes thread params in media messages" , async ( ) => {
474496 const chatId = "-1001234567890" ;
475497 const sendPhoto = vi . fn ( ) . mockResolvedValue ( {
Original file line number Diff line number Diff line change @@ -93,6 +93,11 @@ describe("normalizeTelegramChatId", () => {
9393 expect ( normalizeTelegramChatId ( "123456789" ) ) . toBe ( "123456789" ) ;
9494 } ) ;
9595
96+ it ( "normalizes bare delivery-only group prefixes for numeric chat ids" , ( ) => {
97+ expect ( normalizeTelegramChatId ( "group:-1001234567890" ) ) . toBe ( "-1001234567890" ) ;
98+ expect ( normalizeTelegramChatId ( "group:123456789" ) ) . toBe ( "123456789" ) ;
99+ } ) ;
100+
96101 it ( "returns undefined for empty input" , ( ) => {
97102 expect ( normalizeTelegramChatId ( " " ) ) . toBeUndefined ( ) ;
98103 } ) ;
@@ -111,6 +116,11 @@ describe("normalizeTelegramLookupTarget", () => {
111116 expect ( normalizeTelegramLookupTarget ( "123456789" ) ) . toBe ( "123456789" ) ;
112117 } ) ;
113118
119+ it ( "normalizes bare delivery-only group prefixes for numeric chat ids" , ( ) => {
120+ expect ( normalizeTelegramLookupTarget ( "group:-1001234567890" ) ) . toBe ( "-1001234567890" ) ;
121+ expect ( normalizeTelegramLookupTarget ( "group:123456789" ) ) . toBe ( "123456789" ) ;
122+ } ) ;
123+
114124 it ( "rejects invalid username forms" , ( ) => {
115125 expect ( normalizeTelegramLookupTarget ( "@bad-handle" ) ) . toBeUndefined ( ) ;
116126 expect ( normalizeTelegramLookupTarget ( "bad-handle" ) ) . toBeUndefined ( ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ export type TelegramTarget = {
77const TELEGRAM_NUMERIC_CHAT_ID_REGEX = / ^ - ? \d + $ / ;
88const TELEGRAM_USERNAME_REGEX = / ^ [ A - Z a - z 0 - 9 _ ] { 5 , } $ / i;
99
10+ function normalizeTelegramDeliveryGroupChatId ( raw : string ) : string {
11+ const trimmed = raw . trim ( ) ;
12+ const match = / ^ g r o u p : \s * ( - ? \d + ) $ / i. exec ( trimmed ) ;
13+ return match ?. [ 1 ] ?? trimmed ;
14+ }
15+
1016export function stripTelegramInternalPrefixes ( to : string ) : string {
1117 let trimmed = to . trim ( ) ;
1218 let strippedTelegramPrefix = false ;
@@ -30,7 +36,7 @@ export function stripTelegramInternalPrefixes(to: string): string {
3036}
3137
3238export function normalizeTelegramChatId ( raw : string ) : string | undefined {
33- const stripped = stripTelegramInternalPrefixes ( raw ) ;
39+ const stripped = normalizeTelegramDeliveryGroupChatId ( stripTelegramInternalPrefixes ( raw ) ) ;
3440 if ( ! stripped ) {
3541 return undefined ;
3642 }
@@ -45,7 +51,7 @@ export function isNumericTelegramChatId(raw: string): boolean {
4551}
4652
4753export function normalizeTelegramLookupTarget ( raw : string ) : string | undefined {
48- const stripped = stripTelegramInternalPrefixes ( raw ) ;
54+ const stripped = normalizeTelegramDeliveryGroupChatId ( stripTelegramInternalPrefixes ( raw ) ) ;
4955 if ( ! stripped ) {
5056 return undefined ;
5157 }
You can’t perform that action at this time.
0 commit comments