wiz0u/WTelegramClient

Unable to register

c88667220 opened this issue · 5 comments

When you wait for the verification code, you will make an error and disconnect the connection, and then you cannot continue to register

An exception occured in the reactor: WTelegram.WTException: Could not read payload length : Connection shut down
at WTelegram.Client.Reactor(Stream stream, CancellationTokenSource cts)

RpcError 401 AUTH_KEY_UNREGISTERED

You should give more details about your problem.
Please provide:

  • Version of WTelegramClient and version of .NET you're using
  • Library logs from the start of the program up to the problem
    (see here how to redirect WTelegramClient logs to file)
  • The code of your Config callback or Login method if problem is related to login (but make sure to remove any sensitive information like api_id/hash/phone/password/...)
  • The code around the method call that causes the issue
  • The full exception details/callstack (ex.ToString) if any.
    (place a try..catch() around the suspected faulty call)

using Starksoft.Aspen.Proxy;
using System;
using System.Threading.Tasks;
using TL;
using WTelegram;
using User = TL.User;

class Program
{
private static readonly ManualResetEventSlim _codeReady = new();
static string phone_number = "";
private static User _user;

static async Task Main()
{
    static async Task<string> ReadLineAsync()
    {
        //_codeReady.Reset();
        return await Task.Run(() => Console.ReadLine());
    }

    static string? Config(string what)
    {
        switch (what)
        {
            case "api_id": return "";
            case "api_hash": return "";
            case "phone_number": return phone_number;
            case "verification_code":
                new Thread(() =>
                {
                    while (!Console.KeyAvailable)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    _codeReady.Set();
                }).Start();
                Console.Write("Code: ");
                _codeReady.Reset();
                _codeReady.Wait();
                return ReadLineAsync().Result;
            case "first_name": return "SS";      // if sign-up is required
            case "last_name": return "yy";        // if sign-up is required
            case "password":
                new Thread(() =>
                {
                    while (!Console.KeyAvailable)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    _codeReady.Set();
                }).Start();
                Console.Write("password: ");
                _codeReady.Reset();
                        _codeReady.Wait();
                return ReadLineAsync().Result; // if user has enabled 2FA
            case "session_pathname": return Environment.CurrentDirectory + "\\session\\" + phone_number + ".session";
            default: return null;                  // let WTelegramClient decide the default config
        }
    }

    using var client = new WTelegram.Client(Config);
    client.TcpHandler = async (address, port) =>
    {
        var proxy = new Socks5ProxyClient("127.0.0.1", 1080);
        return proxy.CreateConnection(address, port);
    };

    _user = await client.LoginUserIfNeeded();
    Console.Write($"{_user.first_name + " " + _user.last_name}");


    Console.ReadLine();
}

}

You can log in, you can't register, you will never receive the verification code SMS, and the connection will be disconnected when the verification code is waiting for the verification code

And the same mobile phone number can be registered successfully with Telegramx
Use .NET 6.0, Wtelegram 3.6.1

I'm sorry but I cannot comprehend your problem because you state too many different problems, so it's unclear what you want.
Here are a few hints:

  • RpcError 401 AUTH_KEY_UNREGISTERED => delete your session file and create a new session with login. Not abnormal
  • WTelegram.WTException: Could not read payload length : Connection shut down => probably after some time when you didn't provide the expected verification code, Telegram servers hang up on you. Not abnormal.
  • you will never receive the verification code SMS => Not abnormal. Since February 2023, it's no longer possible to receive verification code by SMS with third-party libraries. you shall receive it via an existing official Telegram client logged-in your number.

As you can see, I see no issue with the library code behaviour itself. So Github Issues is not the place to debug your personal login problems. You may want to discuss this in Telegram support group.

If the above not answer you problem, and you still think there is a problem with the library itself, create a single issue for each problem, and clearly state what you want to achieve, what you did exactly and what you observed that behaves wrongly.

Not to log in, but register with a new mobile phone number