diff --git a/README.md b/README.md index 8c1bc8c..53a7184 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ using Telegrator.Annotations; [MessageHandler] public class HelloHandler : MessageHandler { - public override async Task Execute(IAbstractHandlerContainer container, CancellationToken cancellation) + public override async Task Execute(IHandlerContainer container, CancellationToken cancellation) { await Reply("Hello, world!", cancellationToken: cancellation); return Result.Ok(); @@ -75,10 +75,10 @@ using Telegram.Bot.Types.Enums; using Telegrator.Handlers; using Telegrator.Annotations; -[CommandHandler, CommandAllias("start", "hello"), ChatType(ChatType.Private)] +[CommandHandler, CommandAlias("start", "hello"), ChatType(ChatType.Private)] public class StartCommandHandler : CommandHandler { - public override async Task Execute(IAbstractHandlerContainer container, CancellationToken cancellation) + public override async Task Execute(IHandlerContainer container, CancellationToken cancellation) { await Responce("Welcome!", cancellationToken: cancellation); return Result.Ok(); @@ -95,10 +95,10 @@ bot.Handlers.AddHandler(); using Telegrator.Handlers; using Telegrator.Annotations; -[CommandHandler, CommandAllias("first"), NumericState(SpecialState.NoState)] +[CommandHandler, CommandAlias("first"), NumericState(SpecialState.NoState)] public class StateKeepFirst : CommandHandler { - public override async Task Execute(IAbstractHandlerContainer container, CancellationToken cancellation) + public override async Task Execute(IHandlerContainer container, CancellationToken cancellation) { container.CreateNumericState(); container.ForwardNumericState(); @@ -126,7 +126,7 @@ bot.Handlers.AddHandler(); ## 📚 Documentation & Examples - [Documentation](https://github.com/Rikitav/Telegrator/wiki/) -- [Usage examples (WIP)](https://github.com/Rikitav/Telegrator/tree/master/Examples) +- [Usage examples (WIP)](https://github.com/Rikitav/Telegrator/tree/master/examples) --- diff --git a/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs b/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs index 6e40f2b..ecbc4c0 100644 --- a/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs +++ b/src/Telegrator.Hosting.Web/Hosting.Web/TelegramBotWebHostBuilder.cs @@ -46,7 +46,7 @@ namespace Telegrator.Hosting.Web _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); - _innerBuilder.AddTelegratorWeb(settings); + _innerBuilder.AddTelegratorWeb(); } /// @@ -60,7 +60,7 @@ namespace Telegrator.Hosting.Web _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); - _innerBuilder.AddTelegratorWeb(settings, null, handlers); + _innerBuilder.AddTelegratorWeb(null, handlers); } /// diff --git a/src/Telegrator.Hosting.Web/Program.cs b/src/Telegrator.Hosting.Web/Program.cs new file mode 100644 index 0000000..910d903 --- /dev/null +++ b/src/Telegrator.Hosting.Web/Program.cs @@ -0,0 +1,77 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +using Telegrator.Hosting; +using Telegrator.Hosting.Web; + +namespace Telegrator; + +internal class Program +{ + public static void TelegramBotWebHostBuilder_Example(string[] args) + { + TelegramBotWebHostBuilder builder = TelegramBotWebHost.CreateBuilder(new WebApplicationOptions() + { + Args = args, + ApplicationName = "TelegramBotWebHost example", + }); + + builder.Handlers.CollectHandlersAssemblyWide(); + + builder.Build() + .AddLoggingAdapter() + .SetBotCommands() + .Run(); + } + + public static void WebApplicationBuilder_Example(string[] args) + { + WebApplicationBuilder builder = WebApplication.CreateBuilder(new WebApplicationOptions() + { + Args = args, + ApplicationName = "WebApplication example", + }); + + builder.AddTelegratorWeb(); + builder.Handlers.CollectHandlersAssemblyWide(); + + builder.Build() + .UseTelegratorWeb() + .AddLoggingAdapter() + .SetBotCommands() + .Run(); + } + + public static void TelegramBotHostBuilder_Example(string[] args) + { + TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new HostApplicationBuilderSettings() + { + Args = args, + ApplicationName = "TelegramBotHost example", + }); + + builder.Handlers.CollectHandlersAssemblyWide(); + + builder.Build() + .AddLoggingAdapter() + .SetBotCommands() + .Run(); + } + + public static void HostApplicationBuilder_Example(string[] args) + { + HostApplicationBuilder builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings() + { + Args = args, + ApplicationName = "Host example", + }); + + builder.AddTelegrator(); + builder.Handlers.CollectHandlersAssemblyWide(); + + builder.Build() + .UseTelegrator() + .AddLoggingAdapter() + .SetBotCommands() + .Run(); + } +} diff --git a/src/Telegrator.Hosting.Web/README.md b/src/Telegrator.Hosting.Web/README.md index 94be16d..add827f 100644 --- a/src/Telegrator.Hosting.Web/README.md +++ b/src/Telegrator.Hosting.Web/README.md @@ -16,8 +16,9 @@ --- ## Requirements -- .NET 8.0 or later +- .NET 10.0 or later - ASP.NET Core +- [Telegrator.Hosting](https://github.com/Rikitav/Telegrator) --- @@ -37,10 +38,10 @@ using Telegrator.Hosting; using Telegrator.Hosting.Web; // Creating builder -TelegramBotWebHostBuilder builder = TelegramBotWebHost.CreateBuilder(new TelegramBotWebOptions() +TelegramBotWebHostBuilder builder = TelegramBotWebHost.CreateBuilder(new WebApplicationOptions() { Args = args, - ExceptIntersectingCommandAliases = true + ApplicationName = "Telegrator WebApplication example", }); // Register handlers @@ -61,23 +62,23 @@ telegramBot.Run(); ```json { - "TelegramBotClientOptions": { - "Token": "YOUR_BOT_TOKEN" + "TelegratorOptions": { + "Token": "YOUR_BOT_TOKEN", + "ExceptIntersectingCommandAliases": true } - "TelegratorWebOptions": { + "WebhookerOptioons": { "WebhookUri" = "https://you-public-host.ru/bot", + "SecretToken": "MEDIC_GAMING" "DropPendingUpdates": true } } ``` -- `TelegramBotClientOptions`: Bot token and client settings - --- ## Documentation -- [Telegrator Main Docs](https://github.com/Rikitav/Telegrator) +- [Telegrator Main Repository](https://github.com/Rikitav/Telegrator) - [Getting Started Guide](https://github.com/Rikitav/Telegrator/wiki/Getting-started) - [Annotation Overview](https://github.com/Rikitav/Telegrator/wiki/Annotation-overview) diff --git a/src/Telegrator.Hosting.Web/TypesExtensions.cs b/src/Telegrator.Hosting.Web/TypesExtensions.cs index 6b85ca9..1d6cf25 100644 --- a/src/Telegrator.Hosting.Web/TypesExtensions.cs +++ b/src/Telegrator.Hosting.Web/TypesExtensions.cs @@ -41,11 +41,8 @@ namespace Telegrator /// /// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// - public static IHostApplicationBuilder AddTelegratorWeb(this IHostApplicationBuilder builder, WebApplicationOptions settings, TelegratorOptions? options = null, IHandlersCollection? handlers = null) + public static IHostApplicationBuilder AddTelegratorWeb(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null) { - if (settings is null) - throw new ArgumentNullException(nameof(settings)); - IServiceCollection services = builder.Services; IConfigurationManager configuration = builder.Configuration; diff --git a/src/Telegrator.Hosting/README.md b/src/Telegrator.Hosting/README.md index 7dd686e..db92e30 100644 --- a/src/Telegrator.Hosting/README.md +++ b/src/Telegrator.Hosting/README.md @@ -15,7 +15,7 @@ --- ## Requirements -- .NET 8.0 or later +- .NET 10.0 or later - [Telegrator](https://github.com/Rikitav/Telegrator) --- @@ -35,10 +35,10 @@ dotnet add package Telegrator.Hosting using Telegrator.Hosting; // Creating builder -TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new TelegramBotHostBuilderSettings() +TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new HostApplicationBuilderSettings() { Args = args, - ExceptIntersectingCommandAliases = true + ApplicationName = "TelegramBotHost example", }); // Registerring handlers @@ -59,8 +59,9 @@ telegramBot.Run(); ```json { - "TelegramBotClientOptions": { - "Token": "YOUR_BOT_TOKEN" + "TelegratorOptions": { + "Token": "YOUR_BOT_TOKEN", + "ExceptIntersectingCommandAliases": true }, "HostOptions": { diff --git a/src/Telegrator.Hosting/TypesExtensions.cs b/src/Telegrator.Hosting/TypesExtensions.cs index f1e206f..159bae4 100644 --- a/src/Telegrator.Hosting/TypesExtensions.cs +++ b/src/Telegrator.Hosting/TypesExtensions.cs @@ -48,11 +48,8 @@ public static class HostBuilderExtensions /// /// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// - public static IHostApplicationBuilder AddTelegrator(this IHostApplicationBuilder builder, HostApplicationBuilderSettings settings, TelegratorOptions? options = null, IHandlersCollection? handlers = null) + public static IHostApplicationBuilder AddTelegrator(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null) { - if (settings is null) - throw new ArgumentNullException(nameof(settings)); - IServiceCollection services = builder.Services; IConfigurationManager configuration = builder.Configuration;