0

I write programm which is looking the specific chat for specific messages, if it was found then forward them to another chat. I want to solve troubles with internet connection, after connection is lost more then 1-2 minutes WTelegramCLient doesnt reconnect automaticly. I tried to increase MaxAutoReconnects and tried to catch ReactorError object on client.OnUpdate event, but nothing is changing. After connection is lost client.OnUpdate is not recieved the ReactorError object at all if the there is no internet longer then 5 minutes. I handled SocketException to autoreconnect but its doesnt work sometimes too. How can i handle with it in a proper way?

Program.cs

private static System.Timers.Timer timer;
private static TClient client;

private static void SetTimer()
{
    timer = new System.Timers.Timer(3000);
    timer.Elapsed += OnTimer_Elapsed;
}

private static void OnTimer_Elapsed(object sender, ElapsedEventArgs e)
{
     timer.Stop();
     Connect();
}

private async static void Connect()
{
     client = new TClient();
     try
     {   
         await client.Connect();
         await client.CheckOldMessages();
     }
     catch (SocketException sEx)
     {
         client.Dispose();
         timer.Start();
     }
}

TClient.cs

...
private Client client;
...
public async Task Connect() => await client.LoginUserIfNeeded();

private async Task<object> Client_OnUpdate(IObject arg)
{
   if (arg is not UpdatesBase updates)
       return null;

   updates.CollectUsersChats(users, chats);
   foreach (Update update in updates.UpdateList)
   {
      switch (update)
      {
          case UpdateNewMessage unm when unm.message.Peer.ID == typicalDonetskID:
               await ForwardMessage(unm.message);
               break;
      }
   }
   return null;
}
bDv
  • 1

1 Answers1

0

I've identified a possible reason why you didn't receive ReactorError.

➡️ It's now fixed in prerelease version 3.5.2-dev.1

So please update and tell me if it works better.

There is also an example program demonstrating how to handle ReactorError within the OnOther event, trying to reconnect forever: https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ReactorError.cs

Wizou
  • 1,336
  • 13
  • 24
  • Yes, thank you a lot, now it works good. But new error after successfull reconection has occured: RpcError 401 AUTH_KEY_UNREGISTERED #31EE Error while fetching current user! (AUTH_KEY_UNREGISTERED) It want me to enter verification code that has been sent via telegram app, but my programm in the nearest future will be as windows service and i will not be able always entering this code after it will have been required after internet connection is restored. Is there any methods how to solve this problem? – bDv May 19 '23 at 10:29
  • Don't use StackOverflow to report issues with the library. Make sure you search the internet about this error, and if you still feel the problem is specific to our library, you can open a Github issue. – Wizou May 19 '23 at 12:17