diff --git a/EXAMPLES.md b/EXAMPLES.md index 35a535c..d8fc6dc 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -448,7 +448,7 @@ This is done by activating the experimental `client.CollectAccessHash` system. See [Examples/Program_CollectAccessHash.cs](Examples/Program_CollectAccessHash.cs) for how to enable it, and save/restore them for later use. -### Use a proxy to connect to Telegram +### Use a proxy or MTProxy to connect to Telegram SOCKS/HTTPS proxies can be used through the `client.TcpHandler` delegate and a proxy library like [StarkSoftProxy](https://www.nuget.org/packages/StarkSoftProxy/): ```csharp using var client = new WTelegram.Client(Environment.GetEnvironmentVariable); diff --git a/Examples/Program_ListenUpdates.cs b/Examples/Program_ListenUpdates.cs index 920dfd1..e463eef 100644 --- a/Examples/Program_ListenUpdates.cs +++ b/Examples/Program_ListenUpdates.cs @@ -52,7 +52,7 @@ namespace WTelegramClientTest case UpdateUserStatus uus: Console.WriteLine($"{User(uus.user_id)} is now {uus.status.GetType().Name[10..]}"); break; case UpdateUserName uun: Console.WriteLine($"{User(uun.user_id)} has changed profile name: {uun.first_name} {uun.last_name}"); break; case UpdateUserPhoto uup: Console.WriteLine($"{User(uup.user_id)} has changed profile photo"); break; - default: Console.WriteLine(update.GetType().Name); break; // there are much more update types than the above cases + default: Console.WriteLine(update.GetType().Name); break; // there are much more update types than the above example cases } } diff --git a/FAQ.md b/FAQ.md index 6e4e747..188d5dd 100644 --- a/FAQ.md +++ b/FAQ.md @@ -48,7 +48,7 @@ calling `client.Login(...)` as the user provides the requested configuration ele You can download such full example apps [for WinForms](https://github.com/wiz0u/WTelegramClient/raw/master/Examples/WinForms_app.zip) and [for ASP.NET](https://github.com/wiz0u/WTelegramClient/raw/master/Examples/ASPnet_webapp.zip) -#### 4. Where to get the access_hash? Why the error `CHANNEL_INVALID` or `USER_ID_INVALID`? +#### 4. How to use IDs? Where to get the access_hash? Why the error `CHANNEL_INVALID` or `USER_ID_INVALID`? Having only the ID is **not enough**: An `access_hash` is required by Telegram when dealing with a channel, user, photo, document, etc... This serves as a proof that the logged-in user is entitled to access it (otherwise, anybody with the ID could access it) @@ -206,7 +206,7 @@ In this case, the recommended action would be to dispose the client and recreate you might also get Connection shutdown because your client couldn't send Pings to Telegram in the allotted time. In this case, you can use the `PingInterval` property to increase the delay between pings *(for example 300 seconds instead of 60)*. -5) If you're using an MTProxy, some of them are known to be quite unstable. You may want to try switching to another MTProxy that is more stable. +5) If you're using an [MTProxy](EXAMPLES.md#proxy), some of them are known to be quite unstable. You may want to try switching to another MTProxy that is more stable. #### 12. How to migrate from TLSharp? How to sign-in/sign-up/register account properly? @@ -233,7 +233,7 @@ In particular, it will detect and handle automatically and properly the various * Request to resend the verification code through alternate ways like SMS (if your Config answer an empty "verification_code" initially) * Transient failures, slowness to respond, wrong code/password, checks for encryption key safety, etc.. -Contrary to TLSharp, WTelegramClient supports MTProto v2.0 (more secured), transport obfuscation, protocol security checks, MTProto Proxy, real-time updates, multiple DC connections, API documentation in Intellisense... +Contrary to TLSharp, WTelegramClient supports MTProto v2.0 (more secured), transport obfuscation, protocol security checks, MTProto [Proxy](EXAMPLES.md#proxy), real-time updates, multiple DC connections, API documentation in Intellisense... #### 13. How to host my userbot online? diff --git a/src/Client.cs b/src/Client.cs index 7386ae7..27b4c8a 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -578,11 +578,16 @@ namespace WTelegram if (_bareRpc != null) { var rpc = PullPendingRequest(_bareRpc.msgId); - if ((rpc?.type.IsAssignableFrom(obj.GetType())) != true) + if ((rpc?.type.IsAssignableFrom(obj.GetType())) == true) + { + _bareRpc = null; + rpc.tcs.SetResult(obj); + return; + } + else if (_dcSession.AuthKeyID == 0) throw new ApplicationException($"Received a {obj.GetType()} incompatible with expected bare {rpc?.type}"); - _bareRpc = null; - rpc.tcs.SetResult(obj); - return; + lock (_pendingRpcs) + _pendingRpcs[_bareRpc.msgId] = _bareRpc; } switch (obj) {