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.
This commit is contained in:
parent
4ac19117c1
commit
7290734f2b
@ -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()}`;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user