1

There was such a problem: I ran the program many times and now it throws the following error FloodException: Flood prevention. Telegram now requires your program to do requests again only after 73611 seconds have passed (TimeToWait property). If you think the culprit of this problem may lie in TLSharp's implementation, open a Github issue please. I attach the code below:

using System;
using System.Text;
using System.Windows.Forms;
using TeleSharp.TL;
using TeleSharp.TL.Messages;
using TLSharp.Core;
namespace tgBM
{
    public partial class Form1: Form
    {
        string phone;
        string code;
        int n = 1;
        StringBuilder sb = new StringBuilder ();
        TelegramClient client = new TelegramClient (2646156, "08ec188e0bdee432e568120348f5f13a"); // create a client with parameters
      
        public Form1 ()
        {
            InitializeComponent();
        }

        string str = "";

        public async void authAsync()
        {
            var dialogs = (TLDialogs) await client.GetUserDialogsAsync();
            foreach (var element in dialogs.Chats)
            {
                TLChat chat = element as TLChat;
                if (element is TLChannel)
                {
                    var offset = 0;
                    TLChannel channel = element as TLChannel;
                    if (channel.Title == "TOPLES")
                    {
                        TLChannel ch = element as TLChannel;
                        TLInputPeerChannel inputPeer = new TLInputPeerChannel() {ChannelId = ch.Id, AccessHash = (long) ch.AccessHash};
                        while (n! = 11)
                        {
                            try
                            {
                                TLChannelMessages res = await client.SendRequestAsync <TLChannelMessages>
                                (new TLRequestGetHistory() {Peer = inputPeer, Limit = 20, AddOffset = offset, OffsetId = 0});
                                var msgs = res.Messages;
                                if (res.Count> offset)
                                {
                                    offset + = msgs.Count;
                                    foreach (TLAbsMessage msg in msgs)
                                    {
                                        if (msg is TLMessage)
                                        {
                                            TLMessage message = msg as TLMessage;
                                            str + = n.ToString () + "\ t" + message.Id + "\ t" + message.FromId + "\ t" + message.Message + Environment.NewLine;
                                        }
                                        if (msg is TLMessageService)
                                            continue;
                                        n ++;
                                    }
                                }
                                else
                                    break;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show (ex.Message);
                                break;
                            }
                        }
                    }
                }
                textBox3.Text = str;
            }
        }

        private async void button1_Click (object sender, EventArgs e)
        {
            phone = textBox1.Text;
            await client.ConnectAsync (); // make a connection
            var hash = await client.SendCodeRequestAsync(phone);
        }

        private async void button2_Click (object sender, EventArgs e)
        {
            code = textBox2.Text;
            var user = await client.MakeAuthAsync(phone, await client.SendCodeRequestAsync(phone), code);
            authAsync();
        }
    }
} 
Palle Due
  • 5,929
  • 4
  • 17
  • 32
num0
  • 11
  • 1
  • 2

1 Answers1

0

In a comment, you said are in a testing phase. In this case, you should read https://core.telegram.org/api/auth#test-accounts

According to this page, there are 3 ways to perform tests while limiting the risk for FLOOD_WAIT errors:

  • Connect to the Test servers instead of the Production servers (seems not possible with TLSharp)
  • Use Test accounts with phone numbers 99966XYYYY (only available on Test servers)
  • Connect as a user with the phone number you use to create the API ID/Hash

I can do all that with WTelegramClient (TLSharp is no longer maintained and cannot connect to Telegram servers anymore)

Wizou
  • 1,336
  • 13
  • 24