Support additional connection JSON params with Config("init_params")

This commit is contained in:
Wizou 2023-11-11 12:25:02 +01:00
parent 96ff52fab8
commit 3861255710
3 changed files with 18 additions and 2 deletions

2
.github/dev.yml vendored
View file

@ -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

View file

@ -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<System.Text.Json.JsonElement>(Config("init_params")));
TLConfig = await this.InvokeWithLayer(Layer.Version,
new TL.Methods.InitConnection<Config>
{
flags = TL.Methods.InitConnection<Config>.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;

View file

@ -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); }