From 7290734f2bc59c3fb3335db5cc5ff1f4fe1f2ab2 Mon Sep 17 00:00:00 2001 From: Arne Moor Date: Sat, 6 Dec 2025 03:29:37 +0100 Subject: [PATCH] fix: normalize Telegram phone numbers to E.164 format Fixed extractSenderIdentifier to always add + prefix to phone numbers from GramJS, ensuring they match normalized allowFrom entries. Without this fix, Telegram senders with phone-based identifiers would be blocked when using allowFrom whitelists because: - GramJS returns phone as "123456789" - normalizeAllowFromEntry expects "+123456789" - Comparison fails: telegram:123456789 != telegram:+123456789 Now all phone identifiers are consistently normalized to telegram:+phone. --- src/telegram/inbound.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/telegram/inbound.ts b/src/telegram/inbound.ts index ecceebe52..97c18df5b 100644 --- a/src/telegram/inbound.ts +++ b/src/telegram/inbound.ts @@ -61,7 +61,7 @@ export async function convertTelegramMessage( * * Returns: * - telegram:@username (if username available) - * - telegram:+phone (if phone available) + * - telegram:+phone (if phone available, normalized to E.164) * - telegram:id (numeric Telegram ID as fallback) */ function extractSenderIdentifier(sender: Api.User | Api.Chat): string { @@ -69,7 +69,9 @@ function extractSenderIdentifier(sender: Api.User | Api.Chat): string { return `telegram:@${sender.username}`; } if ("phone" in sender && sender.phone) { - return `telegram:${sender.phone}`; + // Ensure phone has + prefix for E.164 format to match normalized allowFrom entries + const phone = sender.phone.startsWith("+") ? sender.phone : `+${sender.phone}`; + return `telegram:${phone}`; } if ("id" in sender && sender.id) { return `telegram:${sender.id.toString()}`;