public BotAPI(Proxy proxy = null) { Configs = BotManager.Core.Configs; Dialogs = BotManager.Core.Dialogs; Commands = BotManager.Core.Commands; ContextController = new UserInputContextController(); UiController = BotManager.Core.Repository.CreateUiDispatcher(ContextController); UsersController = BotManager.Core.Repository.CreateUserController(); DataParser = new DataParser(); // start telegram api initializing HttpClient httpClient = null; try { BotManager.Core?.LogController?.LogSystem(new DebugMessage($"Start initializing Telegram Bot Api...\r\nUse proxy: {Configs.UseProxy}")); if (Configs.UseProxy) { BotManager.Core?.LogController?.LogImportant(new DebugMessage($"Proxy enabled. Use proxy: <<xxx>>")); // init httpClient httpClient = new HttpClient(); BotManager.Core?.LogController?.LogImportant(new DebugMessage($"Proxy NOT IMPLEMENTED")); } Api = new TelegramBotClient(Configs.BotHash, httpClient); Api.OnMessage += Api_OnMessage; Api.OnCallbackQuery += Api_OnCallbackQuery; Api.OnInlineQuery += Api_OnInlineQuery; Api.OnReceiveError += Api_OnReceiveError; Api.OnReceiveGeneralError += Api_OnReceiveGeneralError; Api.OnUpdate += Api_OnUpdate; // here we get some useful bot info and at the same time // checks if connection established or not. BotManager.Core?.LogController?.LogImportant(new DebugMessage($"Conect Api client with bot token: <<{Configs.BotHash}>> ...")); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); BotInfo = Api.GetMeAsync().Result; BotName = BotInfo.Username; ContextController.SetIgnored(BotInfo.Id); sw.Stop(); BotManager.Core?.LogController? .LogSucces(new DebugMessage($"Conection is cuccess (response time = {sw.Elapsed})\r\n--> Bot Api initialized and ready!")); } catch (Exception e) { BotManager.Core?.LogController?.LogCritical(new DebugMessage("Api initialization failed!", "BotApi()", e)); } finally { httpClient?.Dispose(); } }
public UIDispatcher(UserInputContextController uicc) { // just setup references ContextController = uicc; Configs = BotManager.Core.Configs; Operations = BotManager.Core.Operations; Dialogs = BotManager.Core.Dialogs; CallbackDataParser = BotManager.Core.Repository.CreateCallbackParser(); }