How do I get a list of phone numbers of contacts in TLSharp?

116 Views Asked by At

Now I get a list of phone numbers of my contacts through reflection. Is there any other way to do this?

  var userContacts = await client.GetContactsAsync();

  foreach (var user in userContacts.Users)
  {
      var props = user.GetType().GetProperties();

      foreach (var prop in props)
      {
          if (prop.Name == "Phone")
          {
              listPhones.Add(prop.GetValue(user).ToString());
          }
      }
  }
1

There are 1 best solutions below

0
On BEST ANSWER

TLSharp is no longer maintained. You might want to switch to WTelegramClient which is similar but better.
Then it would be as simple as:

var contacts = await client.Contacts_GetContacts(0);
foreach (var (id, user) in contacts.users)
    listPhones.Add(user.phone);