diff --git a/.github/dev.yml b/.github/dev.yml index dd9224a..9d831ea 100644 --- a/.github/dev.yml +++ b/.github/dev.yml @@ -1,7 +1,7 @@ pr: none trigger: [ master ] -name: 3.5.9-dev.$(Rev:r) +name: 3.5.10-dev.$(Rev:r) pool: vmImage: ubuntu-latest diff --git a/src/Client.cs b/src/Client.cs index 0b15116..67b3f0d 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -143,6 +143,7 @@ namespace WTelegram "lang_code" => CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, "user_id" => "-1", "verification_code" or "email_verification_code" or "password" => AskConfig(what), + "init_params" => "{}", _ => null // api_id api_hash phone_number... it's up to you to reply to these correctly }; @@ -857,9 +858,11 @@ namespace WTelegram await CreateAuthorizationKey(this, _dcSession); var keepAliveTask = KeepAlive(_cts.Token); + var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonSerializer.Deserialize(Config("init_params"))); TLConfig = await this.InvokeWithLayer(Layer.Version, new TL.Methods.InitConnection { + flags = TL.Methods.InitConnection.Flags.has_params, api_id = _session.ApiId, device_model = Config("device_model"), system_version = Config("system_version"), @@ -867,6 +870,7 @@ namespace WTelegram system_lang_code = Config("system_lang_code"), lang_pack = Config("lang_pack"), lang_code = Config("lang_code"), + params_ = initParams, query = new TL.Methods.Help_GetConfig() }); _session.DcOptions = TLConfig.dc_options; diff --git a/src/TL.Helpers.cs b/src/TL.Helpers.cs index 694ac24..746a734 100644 --- a/src/TL.Helpers.cs +++ b/src/TL.Helpers.cs @@ -639,7 +639,19 @@ namespace TL } partial class JsonObjectValue { public override string ToString() => $"{HttpUtility.JavaScriptStringEncode(key, true)}:{value}"; } - partial class JSONValue { public abstract object ToNative(); } + partial class JSONValue { public abstract object ToNative(); + private static JsonObjectValue FromJsonProperty(System.Text.Json.JsonProperty p) => new() { key = p.Name, value = FromJsonElement(p.Value) }; + public static JSONValue FromJsonElement(System.Text.Json.JsonElement elem) => elem.ValueKind switch + { + System.Text.Json.JsonValueKind.True or + System.Text.Json.JsonValueKind.False => new JsonBool { value = elem.GetBoolean() }, + System.Text.Json.JsonValueKind.Object => new JsonObject { value = elem.EnumerateObject().Select(FromJsonProperty).ToArray() }, + System.Text.Json.JsonValueKind.Array => new JsonArray { value = elem.EnumerateArray().Select(FromJsonElement).ToArray() }, + System.Text.Json.JsonValueKind.String => new JsonString { value = elem.GetString() }, + System.Text.Json.JsonValueKind.Number => new JsonNumber { value = elem.GetDouble() }, + _ => new JsonNull(), + }; + } partial class JsonNull { public override object ToNative() => null; public override string ToString() => "null"; } partial class JsonBool { public override object ToNative() => value; public override string ToString() => value ? "true" : "false"; } partial class JsonNumber { public override object ToNative() => value; public override string ToString() => value.ToString(CultureInfo.InvariantCulture); }