From b94ec0abcaeca5acf3c03616368096d765e3ee1d Mon Sep 17 00:00:00 2001 From: Wizou Date: Fri, 29 Oct 2021 23:27:23 +0200 Subject: [PATCH] clarification on Config null behavior --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ac67b9f..17d519f 100644 --- a/README.md +++ b/README.md @@ -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 should be provided 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)