clarification on Config null behavior

This commit is contained in:
Wizou 2021-10-29 23:27:23 +02:00
parent df2fe83ad2
commit b94ec0abca

View file

@ -47,7 +47,7 @@ static string Config(string what)
case "api_id": return "YOUR_API_ID";
case "api_hash": return "YOUR_API_HASH";
case "phone_number": return "+12025550156";
case "verification_code": return null; // let WTelegramClient ask the user with a console prompt
case "verification_code": Console.Write("Code: "); return Console.ReadLine();
case "first_name": return "John"; // if sign-up is required
case "last_name": return "Doe"; // if sign-up is required
case "password": return "secret!"; // if user has enabled 2FA
@ -57,9 +57,12 @@ static string Config(string what)
...
using var client = new WTelegram.Client(Config);
```
There are other configuration items that are queried to your method but returning `null` let WTelegramClient choose a default adequate value. Those shown above are the only ones that have no default values and should be provided by your method.
There are other configuration items that are queried to your method but returning `null` let WTelegramClient choose a default adequate value.
Those shown above are the only ones that have no default values and <u>should be provided</u> by your method.
Returning `null` for verification_code or password will show a prompt for console apps, or an error otherwise.
Another simpler approach is to pass `Environment.GetEnvironmentVariable` as the config callback and define the above items as environment variables.
Another simpler approach is to pass `Environment.GetEnvironmentVariable` as the config callback and define the configuration items as environment variables.
Undefined variables get the default `null` behavior.
Finally, if you want to redirect the library logs to your logger instead of the Console, you can install a delegate in the `WTelegram.Helpers.Log` static property.
Its `int` argument is the log severity, compatible with the classic [LogLevel enum](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel)