From 1f1aa1f0ee6d70eca4a5fe83903f16ec4d32a9c6 Mon Sep 17 00:00:00 2001 From: Florian Zevedei Date: Wed, 3 Jul 2024 15:56:50 +0200 Subject: [PATCH 1/3] Adding throwPendingUpdates to QuickStart in BBB --- TelegramBotBase/Builder/BotBaseBuilder.cs | 12 ++++++------ .../Builder/Interfaces/IAPIKeySelectionStage.cs | 9 ++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/TelegramBotBase/Builder/BotBaseBuilder.cs b/TelegramBotBase/Builder/BotBaseBuilder.cs index 1baeba2..3d95e75 100644 --- a/TelegramBotBase/Builder/BotBaseBuilder.cs +++ b/TelegramBotBase/Builder/BotBaseBuilder.cs @@ -73,14 +73,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, } - public IBuildingStage QuickStart(string apiKey, Type startForm) + public IBuildingStage QuickStart(string apiKey, Type startForm, bool throwPendingUpdates = false) { _apiKey = apiKey; _factory = new DefaultStartFormFactory(startForm); DefaultMessageLoop(); - NoProxy(); + NoProxy(throwPendingUpdates); OnlyStart(); @@ -94,7 +94,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, } - public IBuildingStage QuickStart(string apiKey) + public IBuildingStage QuickStart(string apiKey, bool throwPendingUpdates = false) where T : FormBase { _apiKey = apiKey; @@ -102,7 +102,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, DefaultMessageLoop(); - NoProxy(); + NoProxy(throwPendingUpdates); OnlyStart(); @@ -115,14 +115,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, return this; } - public IBuildingStage QuickStart(string apiKey, IStartFormFactory startFormFactory) + public IBuildingStage QuickStart(string apiKey, IStartFormFactory startFormFactory, bool throwPendingUpdates = false) { _apiKey = apiKey; _factory = startFormFactory; DefaultMessageLoop(); - NoProxy(); + NoProxy(throwPendingUpdates); OnlyStart(); diff --git a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs index bcbe23b..45d439f 100644 --- a/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs +++ b/TelegramBotBase/Builder/Interfaces/IAPIKeySelectionStage.cs @@ -20,16 +20,18 @@ public interface IAPIKeySelectionStage /// /// /// + /// Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling. /// - IBuildingStage QuickStart(string apiKey, Type StartForm); + IBuildingStage QuickStart(string apiKey, Type StartForm, bool throwPendingUpdates = false); /// /// Quick and easy way to create a BotBase instance. /// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage /// /// + /// Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling. /// - IBuildingStage QuickStart(string apiKey) where T : FormBase; + IBuildingStage QuickStart(string apiKey , bool throwPendingUpdates = false) where T : FormBase; /// /// Quick and easy way to create a BotBase instance. @@ -37,6 +39,7 @@ public interface IAPIKeySelectionStage /// /// /// + /// Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling. /// - IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory); + IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory, bool throwPendingUpdates = false); } \ No newline at end of file From eb8fad444b6f9d4eba3cee94e48e3dfc776334dd Mon Sep 17 00:00:00 2001 From: Florian Zevedei Date: Wed, 10 Jul 2024 14:25:08 +0200 Subject: [PATCH 2/3] Fix for bots in groups adding/removing --- TelegramBotBase/Base/MessageResult.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TelegramBotBase/Base/MessageResult.cs b/TelegramBotBase/Base/MessageResult.cs index 0b86362..f1224c3 100644 --- a/TelegramBotBase/Base/MessageResult.cs +++ b/TelegramBotBase/Base/MessageResult.cs @@ -21,6 +21,9 @@ public class MessageResult : ResultBase { IsAction = UpdateData.CallbackQuery != null; + if (Message == null) + return; + IsBotCommand = Message.Entities?.Any(a => a.Type == MessageEntityType.BotCommand) ?? false; if (!IsBotCommand) From 7aa40b3e2d3f58a4ff54ba50cc4ba17d1ee75f0a Mon Sep 17 00:00:00 2001 From: Florian Zevedei Date: Wed, 10 Jul 2024 14:25:51 +0200 Subject: [PATCH 3/3] Using Message instead RawData.Message on session creation --- TelegramBotBase/BotBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index 5a50823..c073e21 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -116,7 +116,7 @@ public sealed class BotBase if (ds == null) { ds = await Sessions.StartSession(e.DeviceId); - ds.LastMessage = e.RawData.Message; + ds.LastMessage = e.Message; OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds)); }