{"id":466815,"date":"2025-07-11T21:00:28","date_gmt":"2025-07-11T21:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=466815"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=466815","title":{"rendered":"<span>\u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c \u0431\u043e\u0442\u044b \u043d\u0430 C# \u0438 \u0441 \u0447\u0435\u043c \u0438\u0445 \u0435\u0434\u044f\u0442. TeleBotFramework<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e4c\/477\/fdb\/e4c477fdb98d6055719276b4afcda029.jpg\" width=\"1024\" height=\"1024\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/e4c\/477\/fdb\/e4c477fdb98d6055719276b4afcda029.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e4c\/477\/fdb\/e4c477fdb98d6055719276b4afcda029.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u042f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0443\u0436\u0435 10 \u043b\u0435\u0442, \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 C# \u0438 ASP.Net \u0438 \u0432\u0437\u0431\u0440\u0435\u043b\u043e \u043c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u044d\u0442\u0438 \u0432\u0430\u0448\u0438 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0431\u043e\u0442\u044b \u0438 \u043a\u0430\u043a \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442. <br \/>\u0421\u043f\u043e\u0439\u043b\u0435\u0440: \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u0431\u0441\u0435\u0440\u0432\u0435\u0440 \u0441 webhook \u0438\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 long-pooling.<\/p>\n<p>\u0418 \u043d\u0430\u0447\u0430\u043b \u044f \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0438 \u0435\u0441\u0442\u044c \u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043e\u0431\u0449\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0418 \u043d\u0430 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u0435, \u043d\u0435 \u043d\u0430\u0448\u0451\u043b. \u0412\u043f\u043e\u043b\u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0438\u0441\u043a\u0430\u043b \u0438 \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u043d\u043e \u0447\u0442\u043e \u0443\u0436 \u0442\u0443\u0442 \u043f\u043e\u0434\u0435\u043b\u0430\u0442\u044c, \u0443\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u043b.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0442\u043e \u043c\u0435\u043d\u044f \u0443\u0434\u0438\u0432\u0438\u043b\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043a\u043e\u0434\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u043e\u0442\u043e\u0432, \u044d\u0442\u043e god \u043c\u0435\u0442\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u0438\u0442\u0447-\u043a\u0435\u0439\u0441\u043e\u0432 \u043e\u0434\u0438\u043d \u0432 \u0434\u0440\u0443\u0433\u043e\u043c, \u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0435\u0449\u0451 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b. \u041c\u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0439\u0442\u0438 \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043f\u0443\u0442\u0438. \u0422\u0438\u043f\u0430 \u0442\u0430\u043a\u043e\u0433\u043e, \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439.<\/p>\n<pre><code class=\"cs\"> class Program     {         static TelegramBotClient botClient;          static void Main(string[] args)         {             \/\/ \u0422\u043e\u043a\u0435\u043d \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u0434\u0435             botClient = new TelegramBotClient(\"123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11\");              botClient.OnMessage += Bot_OnMessage;             botClient.StartReceiving();              Console.WriteLine(\"\u0411\u043e\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d. \u041d\u0430\u0436\u043c\u0438\u0442\u0435 Enter \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438...\");             Console.ReadLine();             botClient.StopReceiving();         }          static void Bot_OnMessage(object sender, MessageEventArgs e)         {             var text = e.Message.Text;             if (text == \"\/start\")             {                 botClient.SendTextMessageAsync(e.Message.Chat.Id, \"\u041f\u0440\u0438\u0432\u0435\u0442! \u042f \u0443\u0436\u0430\u0441\u043d\u044b\u0439 \u0431\u043e\u0442.\");             }             else             {                 botClient.SendTextMessageAsync(e.Message.Chat.Id, \"\u042f \u043d\u0435 \u0437\u043d\u0430\u044e \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b :(\");             }         }     }<\/code><\/pre>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u044f \u0445\u043e\u0440\u043e\u0448 \u0432 \u0442\u0435\u043e\u0440\u0438\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432, \u043d\u043e \u0442\u0443\u0442 \u043c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0448\u043b\u0430 \u0438\u0434\u0435\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c command, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u0442\u0430. \u041f\u043e\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043a\u0430\u043a-\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0430. \u041d\u0443 \u0430 \u0434\u043b\u044f \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 DI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e (\u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 .Net 8).<\/p>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/p>\n<pre><code class=\"cs\">public interface ITelegramCommand {     \/\/ \u0418\u043c\u044f \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0435     public static string? Name { get; }     \/\/ \u0415\u0451 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435     public static string? Description { get; }     \/\/ \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0434\u043e \u043b\u0438 \u044d\u0442\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u043a\u043e\u043c\u0430\u043d\u0434     public static bool IsPublic =&gt; true;     \/\/ \u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435     public Task Execute(UpdateInfo update); }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0443\u0442 \u0441\u0442\u0430\u0442\u0438\u043a \u043f\u043e\u043b\u044f, \u043d\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435, \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0451\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0438 \u0435\u0451 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<pre><code class=\"cs\">public interface ICommandFactory {     ITelegramCommand? CreateCommand(string commandName);     IList&lt;CommandInfo&gt; GetCommandList(); }<\/code><\/pre>\n<pre><code class=\"cs\">public class CommandFactory(IServiceProvider serviceProvider) : ICommandFactory {     private readonly IServiceProvider _serviceProvider = serviceProvider;      public ITelegramCommand? CreateCommand(string commandName)     {         return _serviceProvider.GetKeyedService&lt;ITelegramCommand&gt;(commandName);     }      public IList&lt;CommandInfo&gt; GetCommandList()     {         return _serviceProvider.GetKeyedServices&lt;ITelegramCommand&gt;(KeyedService.AnyKey)             .Select(s =&gt;             {                 var type = s.GetType();                 var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static);                 var isPublic = (bool)properties.First(p =&gt; p.Name == nameof(ITelegramCommand.IsPublic)).GetValue(null)!;                 if (!isPublic)                     return null; \/\/ Skip non-public commands                  var name = properties.First(p =&gt; p.Name == nameof(ITelegramCommand.Name)).GetValue(null) as string;                 var description = properties.First(p =&gt; p.Name == nameof(ITelegramCommand.Description)).GetValue(null) as string;                  return new CommandInfo                 {                     Name = name!,                     Description = description!                 };             })             .Where(x =&gt; x is not null)             .ToList();     } }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f instance&#8217;a \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0435\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u0430 \u0443\u0436\u0435 Service Provider \u0434\u043e\u0441\u0442\u0430\u0451\u0442 \u043d\u0443\u0436\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u043e \u0438\u043c\u0435\u043d\u0438.<br \/>\u0422\u0430\u043a \u0436\u0435 \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u043c\u0435\u043d\u044e \u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b help.<\/p>\n<p>\u0410 \u0434\u0430\u043b\u044c\u0448\u0435 \u0435\u0449\u0451 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0432\u0441\u0435\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043a IServiceCollection.<\/p>\n<pre><code class=\"cs\">public static class ModuleExtensions {     public static void AddTelegramFramework(this IServiceCollection services, Assembly[] assembliesToRegisterCommandFrom)     {         services.AddScoped&lt;ICommandFactory, CommandFactory&gt;();         services.AddScoped&lt;ITelegramUpdateHandler, TelegramUpdateHandler&gt;();         services.AddSingleton&lt;IUserSessionManager, UserSessionManager&gt;();         services.AutoRegisterCommands([.. assembliesToRegisterCommandFrom, typeof(ModuleExtensions).Assembly]);     }      private static void AutoRegisterCommands(this IServiceCollection services, Assembly[] assemblies)     {         var type = typeof(ITelegramCommand);         var commandTypes = assemblies.SelectMany(s =&gt; s.GetTypes()).Where((p) =&gt; type.IsAssignableFrom(p) &amp;&amp; p != type).ToList();         var commandList = new List&lt;(string Name, string Description)&gt;();         foreach (var commandType in commandTypes)         {             if (!typeof(ITelegramCommand).IsAssignableFrom(commandType))                 continue;              var nameProperty = commandType.GetProperty(nameof(ITelegramCommand.Name), BindingFlags.Public | BindingFlags.Static);             var name = (string)nameProperty!.GetValue(null)!;              var descriptionProperty = commandType.GetProperty(nameof(ITelegramCommand.Description), BindingFlags.Public | BindingFlags.Static);             var description = (string)descriptionProperty!.GetValue(null)!;              var isPublicProperty = commandType.GetProperty(nameof(ITelegramCommand.IsPublic), BindingFlags.Public | BindingFlags.Static);             var isPublic = (bool)isPublicProperty!.GetValue(null)!;             if (isPublic)                 commandList.Add((name, description));              services.AddKeyedScoped(typeof(ITelegramCommand), name, commandType);         }          var sp = services.BuildServiceProvider();         using var scope = sp.CreateScope();         var bot = scope.ServiceProvider.GetRequiredService&lt;ITelegramBotClient&gt;();         bot.SetMyCommands(             [.. commandList.Select(c =&gt;                 new BotCommand                 {                     Command = c.Name.TrimStart('\/'), \/\/ \/start \u2192 start                     Description = c.Description                 })             ]         );     } }<\/code><\/pre>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0434\u0435\u043b\u0430\u043b\u0438\u0441\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e \u0442\u0438\u043f\u0443. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ITelegramCommand \u0438\u0437 Assembly, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438. \u041f\u043b\u044e\u0441 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b &#8212; help \u0438 cancel.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c Handler \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0442 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c\u0430 \u0438 \u0432\u0441\u0451. \u0410 \u0432\u043e\u0442 \u0438 \u043e\u043d.<\/p>\n<pre><code class=\"cs\">public class TelegramUpdateHandler : ITelegramUpdateHandler {     private readonly ITelegramBotClient _bot;     private readonly ICommandFactory _commandFactory;     private readonly IUserSessionManager _userSessionManager;      public TelegramUpdateHandler(ICommandFactory commandFactory, ITelegramBotClient bot, IUserSessionManager userSessionManager)     {         _commandFactory = commandFactory;         _bot = bot;         _userSessionManager = userSessionManager;     }      public async Task HandleUpdate(Update update)     {          if (update.Message != null)         {             var updateInfo = new UpdateInfo             {                 UserId = update.Message.From!.Id,                 Username = update.Message.From.Username ?? string.Empty,                 FirstName = update.Message.From.FirstName ?? string.Empty,                 LastName = update.Message.From.LastName ?? string.Empty,                 ChatId = update.Message.Chat.Id,                 MessageId = update.Message.MessageId,                 Text = update.Message.Text,             };             if (!string.IsNullOrEmpty(updateInfo.Text) &amp;&amp; updateInfo.Text == CancelCommand.Name)             {                 await _commandFactory.CreateCommand(CancelCommand.Name)!.Execute(updateInfo);                 return;             }              var userSession = _userSessionManager.GetSession(updateInfo.UserId);             string commandName;             if (userSession is null)             {                 if (string.IsNullOrWhiteSpace(update.Message.Text))                 {                     await _bot.SendMessage(update.Message.Chat.Id, $\"Enter command, please\");                     return;                 }                  var commandWithParams = update.Message.Text.Split(' ');                 commandName = commandWithParams[0];             }             else             {                 commandName = userSession.Command;             }              var command = _commandFactory.CreateCommand(commandName);             if (command is null)             {                 await _bot.SendMessage(update.Message.Chat.Id, $\"Unknown command: {commandName}\");                 return;             }              await command.Execute(updateInfo);         }          if (update.CallbackQuery is { } cb)         {             var updateInfo = new UpdateInfo             {                 UserId = update.CallbackQuery.From.Id,                 Username = update.CallbackQuery.From.Username ?? string.Empty,                 FirstName = update.CallbackQuery.From.FirstName ?? string.Empty,                 LastName = update.CallbackQuery.From.LastName ?? string.Empty,                 ChatId = update.CallbackQuery.Message!.Chat.Id,                 MessageId = update.CallbackQuery.Message.Id,                 Text = update.CallbackQuery.Data,                 InlineKeyboardMarkup = update.CallbackQuery.Message.ReplyMarkup,             };             if (string.IsNullOrWhiteSpace(updateInfo.Text))             {                 await _bot.SendMessage(updateInfo.ChatId, $\"empty callback\");                 return;             }              var commandWithParams = updateInfo.Text.Split(' ');             var command = _commandFactory.CreateCommand(commandWithParams[0]);             if (command is null)             {                 await _bot.SendMessage(updateInfo.ChatId, $\"Unknown command: {updateInfo.Text}\");                 return;             }              await command.Execute(updateInfo);         }     }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0443\u0436\u0435 \u043d\u0435 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0438 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f, \u043d\u043e \u043f\u043e\u043a\u0430 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435, \u043e\u043d\u043e \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043d\u0443\u0436\u0434\u044b.<br \/>\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c Callback&#8217;\u0438, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0435\u0434\u0438\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0434\u043e\u0441\u0442\u0430\u0451\u043c \u043c\u0435\u0442\u0430-\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u043e\u0442\u0430\u043c\u0438, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u041f\u043e\u043a\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043d\u043e\u043f\u043a\u0438, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u043e \u0432\u043e\u0442 \u043d\u0435\u0437\u0430\u0434\u0430\u0447\u0430, \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0432\u0432\u043e\u0434 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0418 \u0442\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f IUserStateManager, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0448\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u043b\u0441\u044f \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<pre><code class=\"cs\">public class UserSessionManager : IUserSessionManager {     private readonly ConcurrentDictionary&lt;long, UserSession&gt; _sessions = new();      public UserSession? GetSession(long userId)     {         return _sessions.GetValueOrDefault(userId);     }      public UserSession CreateOrUpdateSession(long userId, string command, int step, string[]? args = null)     {         return _sessions.AddOrUpdate(userId, _ =&gt; new UserSession(userId, command, step, args), (key, oldValue) =&gt;         {             oldValue.Command = command;             oldValue.Step = step;             oldValue.Arguments = args ?? oldValue.Arguments;             return oldValue;         });     }      public void ClearSession(long userId)     {         _sessions.TryRemove(userId, out _);     } }<\/code><\/pre>\n<p>\u0421\u0443\u0442\u044c \u0435\u0433\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0445\u0438\u0442\u0440\u0430\u044f, \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 State \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0438 \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0430 \u0442\u0430\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0441\u0430\u043c\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0441 \u043d\u0438\u043c. \u0422\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0442\u0443\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e \u0432 Callback \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 64 \u0431\u0430\u0439\u0442\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>\u0410 \u0435\u0449\u0451 \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u044d\u0448 \u0438\u043b\u0438 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043f\u043e\u043a\u0430 \u043c\u043d\u0435 \u0431\u044b\u043b\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044f.<\/p>\n<p>\u0418 \u0432\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0431\u0435\u0437 \u0441\u0442\u0435\u0439\u0442\u0430. \u0421\u0430\u043c\u0430 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f, \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"cs\">internal class StartCommand(ITelegramBotClient bot) : ITelegramCommand {     private readonly ITelegramBotClient _bot = bot;      public static string Name =&gt; \"\/start\";     public static string Description =&gt; \"Start operation\";     public static bool IsPublic =&gt; true;      public async Task Execute(UpdateInfo update)     {         await _bot.SendMessage(update.ChatId, $\"Hello, {update.Username ?? update.FirstName + \" \" + update.LastName}\");     } }<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0442\u0435\u0439\u0442\u0430.<\/p>\n<pre><code class=\"cs\">internal class UserStateExampleCommand(ITelegramBotClient bot, IUserSessionManager userSessionManager) : ITelegramCommand {     private readonly ITelegramBotClient _bot = bot;     private readonly IUserSessionManager _userSessionManager = userSessionManager;      public static string Name =&gt; \"\/resend\";     public static string Description =&gt; \"Resend message to chat\";     public static bool IsPublic =&gt; true;      public async Task Execute(UpdateInfo update)     {         var currentSession = _userSessionManager.GetSession(update.UserId);         var currentStep  = currentSession?.Step ?? 0;         switch (currentStep)         {             case 0:                 await _bot.SendMessage(update.ChatId, \"Hi, enter message and I'll resend it to you\");                 _userSessionManager.CreateOrUpdateSession(update.UserId, Name, 1, [\"arg\"]);                 break;             case 1:                 if (string.IsNullOrWhiteSpace(update.Text))                 {                     await _bot.SendMessage(update.ChatId, \"Please enter a valid message.\");                     return;                 }                 await _bot.SendMessage(update.ChatId, $\"You entered: {update.Text}. Argument was {currentSession!.Arguments[0]}\");                 _userSessionManager.ClearSession(update.UserId);                 break;         }     } }<\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a77\/f42\/4c2\/a77f424c247d9039dcfedae46e157b9b.jpg\" width=\"480\" height=\"360\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/a77\/f42\/4c2\/a77f424c247d9039dcfedae46e157b9b.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a77\/f42\/4c2\/a77f424c247d9039dcfedae46e157b9b.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u043e\u0442 \u043d\u0435\u0445\u0438\u0442\u0440\u044b\u0439 \u043d\u0430\u0431\u043e\u0440, \u043c\u043e\u0436\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0431\u043e\u0442\u0430, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0440\u0430\u0449\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. \u0412\u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043b\u044e\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b \u0438 \u043b\u0435\u0433\u043a\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u0435\u043d\u044e<\/p>\n<\/li>\n<li>\n<p>\u041b\u0451\u0433\u043a\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 &#171;god-\u043c\u0435\u0442\u043e\u0434\u043e\u0432&#187;<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0430 GitHub &#8212; <a href=\"https:\/\/github.com\/Alados\/TeleBotFramework\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/Alados\/TeleBotFramework<\/a><br \/>Nuget &#8212; <a href=\"https:\/\/www.nuget.org\/packages\/TeleBotFramework\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.nuget.org\/packages\/TeleBotFramework<\/a><\/p>\n<p>\u0423\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0445 \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e \u043a\u043e\u0434\u0430, \u043d\u043e \u044f \u043f\u0438\u0441\u0430\u043b \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u0432 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0434\u043b\u044f \u0441\u0435\u0431\u044f. \u041c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f.<\/p>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0434\u043d\u0435\u0439 \u043d\u0430\u043f\u0438\u0448\u0443, \u043a\u0430\u043a \u044f \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u043b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0438\u0441\u0430\u043b\u0430\u0441\u044c \u0442\u043e \u043e\u043d\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430, \u043d\u043e \u0432\u0434\u0440\u0443\u0433 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f. \u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0437\u0432\u0451\u0437\u0434\u043e\u0447\u043a\u0443.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/359\/2f3\/bbd\/3592f3bbd403e81e46328766025d2400.png\" alt=\"\u0410 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043c\u043d\u0435 \u0438 \u043d\u0435 \u043d\u0430\u0434\u043e\" title=\"\u0410 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043c\u043d\u0435 \u0438 \u043d\u0435 \u043d\u0430\u0434\u043e\" width=\"1644\" height=\"1074\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/359\/2f3\/bbd\/3592f3bbd403e81e46328766025d2400.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/359\/2f3\/bbd\/3592f3bbd403e81e46328766025d2400.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0410 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043c\u043d\u0435 \u0438 \u043d\u0435 \u043d\u0430\u0434\u043e<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/927042\/\"> https:\/\/habr.com\/ru\/articles\/927042\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u042f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0443\u0436\u0435 10 \u043b\u0435\u0442, \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 C# \u0438 ASP.Net \u0438 \u0432\u0437\u0431\u0440\u0435\u043b\u043e \u043c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u044d\u0442\u0438 \u0432\u0430\u0448\u0438 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0431\u043e\u0442\u044b \u0438 \u043a\u0430\u043a \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442. <br \/>\u0421\u043f\u043e\u0439\u043b\u0435\u0440: \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u0431\u0441\u0435\u0440\u0432\u0435\u0440 \u0441 webhook \u0438\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 long-pooling.<\/p>\n<p>\u0418 \u043d\u0430\u0447\u0430\u043b \u044f \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0438 \u0435\u0441\u0442\u044c \u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043e\u0431\u0449\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0418 \u043d\u0430 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u0435, \u043d\u0435 \u043d\u0430\u0448\u0451\u043b. \u0412\u043f\u043e\u043b\u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0438\u0441\u043a\u0430\u043b \u0438 \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u043d\u043e \u0447\u0442\u043e \u0443\u0436 \u0442\u0443\u0442 \u043f\u043e\u0434\u0435\u043b\u0430\u0442\u044c, \u0443\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u043b.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0442\u043e \u043c\u0435\u043d\u044f \u0443\u0434\u0438\u0432\u0438\u043b\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043a\u043e\u0434\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u043e\u0442\u043e\u0432, \u044d\u0442\u043e god \u043c\u0435\u0442\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u0438\u0442\u0447-\u043a\u0435\u0439\u0441\u043e\u0432 \u043e\u0434\u0438\u043d \u0432 \u0434\u0440\u0443\u0433\u043e\u043c, \u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0435\u0449\u0451 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b. \u041c\u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0439\u0442\u0438 \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043f\u0443\u0442\u0438. \u0422\u0438\u043f\u0430 \u0442\u0430\u043a\u043e\u0433\u043e, \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439.<\/p>\n<pre><code class=\"cs\"> class Program     {         static TelegramBotClient botClient;          static void Main(string[] args)         {             \/\/ \u0422\u043e\u043a\u0435\u043d \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u0434\u0435             botClient = new TelegramBotClient(\"123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11\");              botClient.OnMessage += Bot_OnMessage;             botClient.StartReceiving();              Console.WriteLine(\"\u0411\u043e\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d. \u041d\u0430\u0436\u043c\u0438\u0442\u0435 Enter \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438...\");             Console.ReadLine();             botClient.StopReceiving();         }          static void Bot_OnMessage(object sender, MessageEventArgs e)         {             var text = e.Message.Text;             if (text == \"\/start\")             {                 botClient.SendTextMessageAsync(e.Message.Chat.Id, \"\u041f\u0440\u0438\u0432\u0435\u0442! \u042f \u0443\u0436\u0430\u0441\u043d\u044b\u0439 \u0431\u043e\u0442.\");             }             else             {                 botClient.SendTextMessageAsync(e.Message.Chat.Id, \"\u042f \u043d\u0435 \u0437\u043d\u0430\u044e \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b :(\");             }         }     }<\/code><\/pre>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u044f \u0445\u043e\u0440\u043e\u0448 \u0432 \u0442\u0435\u043e\u0440\u0438\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432, \u043d\u043e \u0442\u0443\u0442 \u043c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0448\u043b\u0430 \u0438\u0434\u0435\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c command, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u0442\u0430. \u041f\u043e\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043a\u0430\u043a-\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0430. \u041d\u0443 \u0430 \u0434\u043b\u044f \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 DI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e (\u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 .Net 8).<\/p>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/p>\n<pre><code class=\"cs\">public interface ITelegramCommand {     \/\/ \u0418\u043c\u044f \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0435     public static string? Name { get; }     \/\/ \u0415\u0451 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435     public static string? Description { get; }     \/\/ \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0434\u043e \u043b\u0438 \u044d\u0442\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u043a\u043e\u043c\u0430\u043d\u0434     public static bool IsPublic =&gt; true;     \/\/ \u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435     public Task Execute(UpdateInfo update); }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0443\u0442 \u0441\u0442\u0430\u0442\u0438\u043a \u043f\u043e\u043b\u044f, \u043d\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435, \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0451\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0438 \u0435\u0451 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<pre><code class=\"cs\">public interface ICommandFactory {     ITelegramCommand? CreateCommand(string commandName);     IList&lt;CommandInfo&gt; GetCommandList(); }<\/code><\/pre>\n<pre><code class=\"cs\">public class CommandFactory(IServiceProvider serviceProvider) : ICommandFactory {     private readonly IServiceProvider _serviceProvider = serviceProvider;      public ITelegramCommand? CreateCommand(string commandName)     {         return _serviceProvider.GetKeyedService&lt;ITelegramCommand&gt;(commandName);     }      public IList&lt;CommandInfo&gt; GetCommandList()     {         return _serviceProvider.GetKeyedServices&lt;ITelegramCommand&gt;(KeyedService.AnyKey)             .Select(s =&gt;             {                 var type = s.GetType();                 var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static);                 var isPublic = (bool)properties.First(p =&gt; p.Name == nameof(ITelegramCommand.IsPublic)).GetValue(null)!;                 if (!isPublic)                     return null; \/\/ Skip non-public commands                  var name = properties.First(p =&gt; p.Name == nameof(ITelegramCommand.Name)).GetValue(null) as string;                 var description = properties.First(p =&gt; p.Name == nameof(ITelegramCommand.Description)).GetValue(null) as string;                  return new CommandInfo                 {                     Name = name!,                     Description = description!                 };             })             .Where(x =&gt; x is not null)             .ToList();     } }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f instance&#8217;a \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0435\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u0430 \u0443\u0436\u0435 Service Provider \u0434\u043e\u0441\u0442\u0430\u0451\u0442 \u043d\u0443\u0436\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u043e \u0438\u043c\u0435\u043d\u0438.<br \/>\u0422\u0430\u043a \u0436\u0435 \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u043c\u0435\u043d\u044e \u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b help.<\/p>\n<p>\u0410 \u0434\u0430\u043b\u044c\u0448\u0435 \u0435\u0449\u0451 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0432\u0441\u0435\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043a IServiceCollection.<\/p>\n<pre><code class=\"cs\">public static class ModuleExtensions {     public static void AddTelegramFramework(this IServiceCollection services, Assembly[] assembliesToRegisterCommandFrom)     {         services.AddScoped&lt;ICommandFactory, CommandFactory&gt;();         services.AddScoped&lt;ITelegramUpdateHandler, TelegramUpdateHandler&gt;();         services.AddSingleton&lt;IUserSessionManager, UserSessionManager&gt;();         services.AutoRegisterCommands([.. assembliesToRegisterCommandFrom, typeof(ModuleExtensions).Assembly]);     }      private static void AutoRegisterCommands(this IServiceCollection services, Assembly[] assemblies)     {         var type = typeof(ITelegramCommand);         var commandTypes = assemblies.SelectMany(s =&gt; s.GetTypes()).Where((p) =&gt; type.IsAssignableFrom(p) &amp;&amp; p != type).ToList();         var commandList = new List&lt;(string Name, string Description)&gt;();         foreach (var commandType in commandTypes)         {             if (!typeof(ITelegramCommand).IsAssignableFrom(commandType))                 continue;              var nameProperty = commandType.GetProperty(nameof(ITelegramCommand.Name), BindingFlags.Public | BindingFlags.Static);             var name = (string)nameProperty!.GetValue(null)!;              var descriptionProperty = commandType.GetProperty(nameof(ITelegramCommand.Description), BindingFlags.Public | BindingFlags.Static);             var description = (string)descriptionProperty!.GetValue(null)!;              var isPublicProperty = commandType.GetProperty(nameof(ITelegramCommand.IsPublic), BindingFlags.Public | BindingFlags.Static);             var isPublic = (bool)isPublicProperty!.GetValue(null)!;             if (isPublic)                 commandList.Add((name, description));              services.AddKeyedScoped(typeof(ITelegramCommand), name, commandType);         }          var sp = services.BuildServiceProvider();         using var scope = sp.CreateScope();         var bot = scope.ServiceProvider.GetRequiredService&lt;ITelegramBotClient&gt;();         bot.SetMyCommands(             [.. commandList.Select(c =&gt;                 new BotCommand                 {                     Command = c.Name.TrimStart('\/'), \/\/ \/start \u2192 start                     Description = c.Description                 })             ]         );     } }<\/code><\/pre>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0434\u0435\u043b\u0430\u043b\u0438\u0441\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e \u0442\u0438\u043f\u0443. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ITelegramCommand \u0438\u0437 Assembly, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438. \u041f\u043b\u044e\u0441 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b &#8212; help \u0438 cancel.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c Handler \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0442 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c\u0430 \u0438 \u0432\u0441\u0451. \u0410 \u0432\u043e\u0442 \u0438 \u043e\u043d.<\/p>\n<pre><code class=\"cs\">public class TelegramUpdateHandler : ITelegramUpdateHandler {     private readonly ITelegramBotClient _bot;     private readonly ICommandFactory _commandFactory;     private readonly IUserSessionManager _userSessionManager;      public TelegramUpdateHandler(ICommandFactory commandFactory, ITelegramBotClient bot, IUserSessionManager userSessionManager)     {         _commandFactory = commandFactory;         _bot = bot;         _userSessionManager = userSessionManager;     }      public async Task HandleUpdate(Update update)     {          if (update.Message != null)         {             var updateInfo = new UpdateInfo             {                 UserId = update.Message.From!.Id,                 Username = update.Message.From.Username ?? string.Empty,                 FirstName = update.Message.From.FirstName ?? string.Empty,                 LastName = update.Message.From.LastName ?? string.Empty,                 ChatId = update.Message.Chat.Id,                 MessageId = update.Message.MessageId,                 Text = update.Message.Text,             };             if (!string.IsNullOrEmpty(updateInfo.Text) &amp;&amp; updateInfo.Text == CancelCommand.Name)             {                 await _commandFactory.CreateCommand(CancelCommand.Name)!.Execute(updateInfo);                 return;             }              var userSession = _userSessionManager.GetSession(updateInfo.UserId);             string commandName;             if (userSession is null)             {                 if (string.IsNullOrWhiteSpace(update.Message.Text))                 {                     await _bot.SendMessage(update.Message.Chat.Id, $\"Enter command, please\");                     return;                 }                  var commandWithParams = update.Message.Text.Split(' ');                 commandName = commandWithParams[0];             }             else             {                 commandName = userSession.Command;             }              var command = _commandFactory.CreateCommand(commandName);             if (command is null)             {                 await _bot.SendMessage(update.Message.Chat.Id, $\"Unknown command: {commandName}\");                 return;             }              await command.Execute(updateInfo);         }          if (update.CallbackQuery is { } cb)         {             var updateInfo = new UpdateInfo             {                 UserId = update.CallbackQuery.From.Id,                 Username = update.CallbackQuery.From.Username ?? string.Empty,                 FirstName = update.CallbackQuery.From.FirstName ?? string.Empty,                 LastName = update.CallbackQuery.From.LastName ?? string.Empty,                 ChatId = update.CallbackQuery.Message!.Chat.Id,                 MessageId = update.CallbackQuery.Message.Id,                 Text = update.CallbackQuery.Data,                 InlineKeyboardMarkup =<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-466815","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=466815"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466815\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}