diff --git a/EXAMPLES.md b/EXAMPLES.md index 9c5b463..290879e 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -11,7 +11,7 @@ await client.LoginUserIfNeeded(); ``` In this case, environment variables are used for configuration so make sure to -go to your **Project Properties > Debug > Environment variables** +go to your **Project Properties > Debug > Launch Profiles > Environment variables** and add at least these variables with adequate values: **api_id, api_hash, phone_number** Remember that these are just simple example codes that you should adjust to your needs. @@ -389,9 +389,9 @@ var chat = chats.chats[1234567890]; // the target chat After the above code, once you [have obtained](FAQ.md#access-hash) an `InputUser` or `User`, you can: ```csharp // • Directly add the user to a Chat/Channel/group: -await client.AddChatUser(chat, user); -// You may get exception USER_PRIVACY_RESTRICTED if the user has denied the right to be added to a chat -// or exception USER_NOT_MUTUAL_CONTACT if the user left the chat previously and you want to add him again +var miu = await client.AddChatUser(chat, user); +// You may get exception USER_NOT_MUTUAL_CONTACT if the user left the chat previously and you want to add him again +// or a result with miu.missing_invitees listing users that denied the right to be added to a chat // • Obtain the main invite link for the chat, and send it to the user: var mcf = await client.GetFullChat(chat); diff --git a/Examples/Program_DownloadSavedMedia.cs b/Examples/Program_DownloadSavedMedia.cs index 11e2271..72c1f2b 100644 --- a/Examples/Program_DownloadSavedMedia.cs +++ b/Examples/Program_DownloadSavedMedia.cs @@ -7,7 +7,7 @@ namespace WTelegramClientTest { static class Program_DownloadSavedMedia { - // go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number + // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number static async Task Main(string[] _) { Console.WriteLine("The program will download photos/medias from messages you send/forward to yourself (Saved Messages)"); diff --git a/Examples/Program_GetAllChats.cs b/Examples/Program_GetAllChats.cs index 8d1c442..6e4a9c2 100644 --- a/Examples/Program_GetAllChats.cs +++ b/Examples/Program_GetAllChats.cs @@ -9,7 +9,7 @@ namespace WTelegramClientTest // This code is similar to what you should have obtained if you followed the README introduction // I've just added a few comments to explain further what's going on - // go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number + // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number static string Config(string what) { if (what == "api_id") return Environment.GetEnvironmentVariable("api_id"); diff --git a/Examples/Program_Heroku.cs b/Examples/Program_Heroku.cs index f1baa5a..f1f9cbe 100644 --- a/Examples/Program_Heroku.cs +++ b/Examples/Program_Heroku.cs @@ -75,7 +75,7 @@ namespace WTelegramClientTest var parts = databaseUrl.Split(':', '/', '@'); _sql = new NpgsqlConnection($"User ID={parts[3]};Password={parts[4]};Host={parts[5]};Port={parts[6]};Database={parts[7]};Pooling=true;SSL Mode=Require;Trust Server Certificate=True;"); _sql.Open(); - using (var create = new NpgsqlCommand($"CREATE TABLE IF NOT EXISTS WTelegram_sessions (name text NOT NULL PRIMARY KEY, data bytea)", _sql)) + using (var create = new NpgsqlCommand("CREATE TABLE IF NOT EXISTS WTelegram_sessions (name text NOT NULL PRIMARY KEY, data bytea)", _sql)) create.ExecuteNonQuery(); using var cmd = new NpgsqlCommand($"SELECT data FROM WTelegram_sessions WHERE name = '{_sessionName}'", _sql); using var rdr = cmd.ExecuteReader(); @@ -134,7 +134,7 @@ HOW TO USE AND DEPLOY THIS EXAMPLE HEROKU USERBOT: - In Visual Studio, Clone the Heroku git repository and add some standard .gitignore .gitattributes files - In this repository folder, create a new .NET Console project with this Program.cs file - Add these Nuget packages: WTelegramClient and Npgsql -- In Project properties > Debug > Environment variables, configure the same values for DATABASE_URL, api_hash, phone_number +- In Project properties > Debug > Launch Profiles > Environment variables, configure the same values for DATABASE_URL, api_hash, phone_number - Run the project in Visual Studio. The first time, it should ask you interactively for elements to complete the connection - On the following runs, the PostgreSQL database contains the session data and it should connect automatically - You can test the userbot by sending him "Ping" in private message (or saved messages). It should respond with "Pong" diff --git a/Examples/Program_ListenUpdates.cs b/Examples/Program_ListenUpdates.cs index 1233764..05f7f28 100644 --- a/Examples/Program_ListenUpdates.cs +++ b/Examples/Program_ListenUpdates.cs @@ -10,7 +10,7 @@ namespace WTelegramClientTest static WTelegram.UpdateManager Manager; static User My; - // go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number + // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number static async Task Main(string[] _) { Console.WriteLine("The program will display updates received for the logged-in user. Press any key to terminate"); diff --git a/Examples/Program_ReactorError.cs b/Examples/Program_ReactorError.cs index ce0e629..370da34 100644 --- a/Examples/Program_ReactorError.cs +++ b/Examples/Program_ReactorError.cs @@ -8,7 +8,7 @@ namespace WTelegramClientTest { static WTelegram.Client Client; - // go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number + // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number static async Task Main(string[] _) { Console.WriteLine("The program demonstrate how to handle ReactorError. Press any key to terminate"); diff --git a/Examples/Program_SecretChats.cs b/Examples/Program_SecretChats.cs index bebd5ac..cff9092 100644 --- a/Examples/Program_SecretChats.cs +++ b/Examples/Program_SecretChats.cs @@ -16,7 +16,7 @@ namespace WTelegramClientTest static readonly Dictionary Users = []; static readonly Dictionary Chats = []; - // go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number + // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number static async Task Main() { Helpers.Log = (l, s) => System.Diagnostics.Debug.WriteLine(s); diff --git a/src/TL.cs b/src/TL.cs index 6d620ed..209a642 100644 --- a/src/TL.cs +++ b/src/TL.cs @@ -80,7 +80,7 @@ namespace TL return reader.ReadTL(ctorNb); #else if (ctorNb == 0) ctorNb = reader.ReadUInt32(); - if (ctorNb == Layer.GZipedCtor) return reader.ReadTLGzipped(); + if (ctorNb == Layer.GZipedCtor) return (IObject)reader.ReadTLGzipped(typeof(IObject)); if (!Layer.Table.TryGetValue(ctorNb, out var type)) throw new WTelegram.WTException($"Cannot find type for ctor #{ctorNb:x}"); if (type == null) return null; // nullable ctor (class meaning is associated with null) diff --git a/src/UpdateManager.cs b/src/UpdateManager.cs index 2323148..5bf0b0e 100644 --- a/src/UpdateManager.cs +++ b/src/UpdateManager.cs @@ -58,7 +58,7 @@ namespace WTelegram _onUpdate = onUpdate; _collector = collector ?? new Services.CollectorPeer(Users = [], Chats = []); - if (state == null) + if (state == null || state.Count < 3) _local = new() { [L_SEQ] = new() { access_hash = UndefinedSeqDate }, [L_QTS] = new(), [L_PTS] = new() }; else _local = state as Dictionary ?? new Dictionary(state); diff --git a/src/WTelegramClient.csproj b/src/WTelegramClient.csproj index b528e74..d41f79d 100644 --- a/src/WTelegramClient.csproj +++ b/src/WTelegramClient.csproj @@ -43,15 +43,18 @@ --> - + - + + + +