TLSharp icon indicating copy to clipboard operation
TLSharp copied to clipboard

Check phone number for having Telegram or not

Open mehdiyahyavi opened this issue 7 years ago • 10 comments

hi. i want to check a lot of number ( about 1000) for Registered on telegram or not. I'm use the code :


OpenFileDialog checkTl = new OpenFileDialog();
            checkTl.Filter = "TextFiles(.txt)|*.txt";
            DialogResult txtTl = checkTl.ShowDialog();
            if (txtTl == DialogResult.OK)
            {
                var tr = new StreamReader(checkTl.FileName).ReadToEnd();
                TextReader text = new StreamReader(checkTl.FileName);
                var lines = tr.Split(new char[] { '\n' });
                int count = lines.Count();
                await client.ConnectAsync();
                int i = 1;
                while (i < count)
                {

                    string number = text.ReadLine().Trim();
                    if (string.IsNullOrWhiteSpace(number)) goto End;
                    //Thread.Sleep(1000);
                    
                    bool checkPhone = await client.IsPhoneRegisteredAsync(number);
                    if (checkPhone)
                    {
                        list_registered.Text += number + "\n";
                        Application.DoEvents();
                    }
                    else
                    {
                        list_notRegistered.Text += number + "\n";
                        Application.DoEvents();
                    }
                    End:
                    i++;
                }
            }

in this code, my application get numbers from txt file and checked them. but after check 5 or 10 numbers, show me exception :

TLSharp.Core.Network.FloodException: 'Flood prevention. Telegram now requires your program to do requests again only after 292 seconds have passed (TimeToWait property). If you think the culprit of this problem may lie in TLSharp's implementation, open a Github issue please.'

any other way to solve my problem ?

mehdiyahyavi avatar May 06 '17 23:05 mehdiyahyavi

This is a limitation put in place by Telegram, not @sochix . When doing many operations at once, you definitely want to put a Thread.Sleep or await Task.Delay in between each iteration. Also, check for that TimeToWait property as the error message says. If you hit the error, then sleep for that - Thread.Sleep(TimeSpam.FromSeconds(TimeToWait));

If you aren't careful (like me!) you'll end up being blocked for over 24 hours.

By the way, a slightly simpler way to read each line of a file:

var line = "";
using (var sr = new StreamReader(fileName))
{
   while ((line = sr.ReadLine()) != null) //this will loop through each line of the file, ending when the file is complete
   {
      //do something with your line here.
   }
}// because of the using statement, your stream reader is automatically disposed when done, so your file won't stay locked.

parabola949 avatar May 12 '17 19:05 parabola949

thanks for replay but i saw a C# winform application that check number to having telegram or not(only see the compiled app, not code) it's work very fast without any delay. i can say that app, check more than 500 numbers in a minute. and now my Q: @parabola949 is there another way to check number ?

mehdiyahyavi avatar May 12 '17 19:05 mehdiyahyavi

Technically, the Telegram limits are supposed to be for when calling the same method with the same parameters multiple times. On each iteration, do a console.writeline and make sure it's actually advancing through the numbers. Also, if you are running this (debug) many times in a row, then you'll be checking the same numbers over and over, which upsets the Telegram​ API.

Try a different set of numbers just for fun, make sure they are all unique, then see what happens.

I'm on my way home now, but if you are still having trouble, I'll toss a method together when I get home.

parabola949 avatar May 12 '17 19:05 parabola949

hi @parabola949 , i have the same problem, can you send to me a method to solve problem?

hagilani avatar Jun 10 '17 07:06 hagilani

Hi @hagilani this is not a TLSharp problem. this is Telegram core limit. no solution found

mehdiyahyavi avatar Jun 10 '17 14:06 mehdiyahyavi

Hi, does anybody know how long Thread.Sleep should be between each API request ? I tried 10 sek, but FloodException appears anyway ? Is there any way to run IsPhoneRegisteredAsync() for several hundreds of numbers? Thread.Sleep > 10sek isnt really userfriendly for a application, is it ?

Thank you very much

mHCio avatar Aug 03 '17 06:08 mHCio

@mHCio Did you found the solution?

ReaGet avatar Oct 21 '17 10:10 ReaGet

@ReaGet not really... currently i use this: TLRequestImportContacts requestImportContacts = new TLRequestImportContacts(); requestImportContacts.contacts = new TLVector<TLInputPhoneContact>(); requestImportContacts.contacts.lists.Add(new TLInputPhoneContact() { phone = telegNr, first_name = member.Name, last_name = member.FamilyName }); var o2 = await TelegramHelper.Instance._client.SendRequestAsync<TLImportedContacts>(requestImportContacts);

I try to import the number to my contacts, if the import works -> number has telegram, if not the number doesnt use telegram. You get anyway a floodexception, but after more iterations as with IsPhoneRegisteredAsync().

I cant agree with he statement from @parabola949, i test it with unique parameters/numbers - that doesn`t affect FloodException !

mHCio avatar Oct 23 '17 06:10 mHCio

Thanks a lot!

2017-10-23 9:48 GMT+03:00 mHCio [email protected]:

@ReaGet https://github.com/reaget not really... currently i use this: TLRequestImportContacts requestImportContacts = new TLRequestImportContacts(); requestImportContacts.contacts = new TLVector<TLInputPhoneContact>(); requestImportContacts.contacts.lists.Add(new TLInputPhoneContact() { phone = telegNr, first_name = member.Name, last_name = member.FamilyName }); var o2 = await TelegramHelper.Instance._ client.SendRequestAsync<TLImportedContacts>(requestImportContacts);

I try to import the number to my contacts, if the import works -> number has telegram, if not the number doesnt use telegram. You get anyway a floodexception, but after more iterations as with IsPhoneRegisteredAsync().

I cant agree with he statement from @parabola949 https://github.com/parabola949, i test it with unique parameters/numbers - that doesn`t affect FloodException !

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sochix/TLSharp/issues/469#issuecomment-338563061, or mute the thread https://github.com/notifications/unsubscribe-auth/AST-BhoLSj0YeckcaR61u9Nkdc5trRv4ks5svDbZgaJpZM4NS8R5 .

ReaGet avatar Oct 23 '17 12:10 ReaGet

I see that in Core exits the method auth.checkPhone (more info) and his description say that:

The method returns an auth.CheckedPhone type object with information on whether an account with such a phone number has already been registered[...]

If you use that, can you solve your problem, or it's crazy to use that? jaja.

SASFMONTOYA avatar Apr 22 '19 16:04 SASFMONTOYA