From 166a35f73297b6e91da337b73edaa8f6dac93455 Mon Sep 17 00:00:00 2001 From: Wizou Date: Tue, 24 Aug 2021 17:24:46 +0200 Subject: [PATCH] added BotAuthIfNeeded --- .github/ci.yml | 2 +- src/Client.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/ci.yml b/.github/ci.yml index 1c49031..7d82778 100644 --- a/.github/ci.yml +++ b/.github/ci.yml @@ -2,7 +2,7 @@ pr: none trigger: - master -name: 0.9.3-ci.$(Rev:r) +name: 0.9.4-ci.$(Rev:r) pool: vmImage: ubuntu-latest diff --git a/src/Client.cs b/src/Client.cs index cf46a73..446be46 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -621,6 +621,18 @@ namespace WTelegram } } + public async Task BotAuthIfNeeded() + { + if (_session.User != null) + return Schema.Deserialize(_session.User); + var authorization = await Auth_ImportBotAuthorization(0, _apiId, _apiHash, Config("bot_token")); + if (authorization is not Auth_Authorization { user: User user }) + throw new ApplicationException("Failed to get Authorization: " + authorization.GetType().Name); + _session.User = user.Serialize(); + _session.Save(); + return user; + } + public async Task UserAuthIfNeeded(CodeSettings settings = null) { if (_session.User != null)