Search code examples
c#tlsharp

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


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());
          }
      }
  }

Solution

  • 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);