Search code examples
telegramphone-numberlibphonenumber

how does telegram checks if a newly joined user number exists in another user contacts list


I've been trying to research this for a while now, what I want is very simple. I'm trying to compare two phone numbers and checks if they match because I'm tryign to implement something similar to telegram, notify a user if one of his contacts list created an account.

My problem is the following:

If I saved my contact using this format 0791234567 and my contact joined using this number +962791234567 both numbers are the same but the first is using local formats and the second using international formats. Does telegram finds these two numbers as a match and sends me a notification indicating that my contact has joined the network ?

I tried to use google library for parsing the numbers, but unfortunately the library doesn't always parse numbers in any format especially if the region was not provided.

Any hints ? or this is just not possible and all numbers must be of a specific format to be able to find a match ?


Solution

  • I think you should have two fields: ‍counry_code and phone_number, and when registering, login, changing the mobile number and etc, get each of the fields individually.

    enter image description here

    for example :

    id | first_name| last_name | password | country_code |phone_number|... 
    ----------------------------------------------------------------------
     1 | alihossein|  shahabi  |  XXXXX   | +98          |9377548654 
    

    or two tables users and phone_numbers :

    id | first_name| last_name | password  |
    ------------------------------------------
     1 | alihossein|  shahabi  |  XXXXX   |
    
    
    id | user_id| country_code | phone_number | active  
    --------------------------------------------------
     1 | 1      |  +98         |  9377541258  | 1   
     2 | 1      |  +98         |  9377543333  | 0