aiho
aiho

Reputation: 21

How to import a list of contacts to telegram from desktop application?

Is there a way to easily import a list of contacts to telegram from desktop application?

I found contacts.importContacts method in Telegram API, but don't understand how to use it.

Upvotes: 2

Views: 15132

Answers (3)

Alveona
Alveona

Reputation: 978

You can try Settings -> Advanced -> Export your telegram data, in the bottom of the window you will see a JSON switch
If you're on Mac OS and don't see Advanced option, then you can try Telegram Lite from Mac App Store

Upvotes: 1

Mohsen Fotouhi
Mohsen Fotouhi

Reputation: 11

var contactList = new TLVector<TLInputPhoneContact>();

            foreach (var mobile in mobileNoList)
            {
                contactList.lists.Add(new TLInputPhoneContact { first_name = mobile.First Name, last_name = mobile.LastName, phone =  mobile.MobileNo.ToString() });
            }

            var req = new TLRequestImportContacts()
            {
                contacts = contactList
            };

            try
            {
                var result = await client.SendRequestAsync<TLImportedContacts>(req);

Upvotes: 0

Alireza Zojaji
Alireza Zojaji

Reputation: 847

If you use TLSharp library in your desktop application, easily you can call contacts.importContacts method in this way:

client = new TelegramClient(apiId, apiHash);
await client.ConnectAsync();
var result = await client.GetContactsAsync();

and for example use the result variable in this way:

var user = result.users.lists
  .Where(x => x.GetType() == typeof(TLUser))
  .Cast<TLUser>()
  .Where(x => x.first_name == textBox1.Text);
if (user.ToList().Count != 0)
{
    foreach (var u in user)
    await client.SendMessageAsync(new TLInputPeerUser() { user_id = u.id }, textBox1.Text);
}

Upvotes: 1

Related Questions