Updated readmes

This commit is contained in:
2026-03-07 20:46:04 +04:00
parent 6c3253107a
commit a3fd6a6007
7 changed files with 103 additions and 30 deletions
+6 -6
View File
@@ -55,7 +55,7 @@ using Telegrator.Annotations;
[MessageHandler] [MessageHandler]
public class HelloHandler : MessageHandler public class HelloHandler : MessageHandler
{ {
public override async Task<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellation) public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
{ {
await Reply("Hello, world!", cancellationToken: cancellation); await Reply("Hello, world!", cancellationToken: cancellation);
return Result.Ok(); return Result.Ok();
@@ -75,10 +75,10 @@ using Telegram.Bot.Types.Enums;
using Telegrator.Handlers; using Telegrator.Handlers;
using Telegrator.Annotations; using Telegrator.Annotations;
[CommandHandler, CommandAllias("start", "hello"), ChatType(ChatType.Private)] [CommandHandler, CommandAlias("start", "hello"), ChatType(ChatType.Private)]
public class StartCommandHandler : CommandHandler public class StartCommandHandler : CommandHandler
{ {
public override async Task<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellation) public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
{ {
await Responce("Welcome!", cancellationToken: cancellation); await Responce("Welcome!", cancellationToken: cancellation);
return Result.Ok(); return Result.Ok();
@@ -95,10 +95,10 @@ bot.Handlers.AddHandler<StartCommandHandler>();
using Telegrator.Handlers; using Telegrator.Handlers;
using Telegrator.Annotations; using Telegrator.Annotations;
[CommandHandler, CommandAllias("first"), NumericState(SpecialState.NoState)] [CommandHandler, CommandAlias("first"), NumericState(SpecialState.NoState)]
public class StateKeepFirst : CommandHandler public class StateKeepFirst : CommandHandler
{ {
public override async Task<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellation) public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
{ {
container.CreateNumericState(); container.CreateNumericState();
container.ForwardNumericState(); container.ForwardNumericState();
@@ -126,7 +126,7 @@ bot.Handlers.AddHandler<StateKeepFirst>();
## 📚 Documentation & Examples ## 📚 Documentation & Examples
- [Documentation](https://github.com/Rikitav/Telegrator/wiki/) - [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)
--- ---
@@ -46,7 +46,7 @@ namespace Telegrator.Hosting.Web
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
_innerBuilder.AddTelegratorWeb(settings); _innerBuilder.AddTelegratorWeb();
} }
/// <summary> /// <summary>
@@ -60,7 +60,7 @@ namespace Telegrator.Hosting.Web
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
_innerBuilder.AddTelegratorWeb(settings, null, handlers); _innerBuilder.AddTelegratorWeb(null, handlers);
} }
/// <summary> /// <summary>
+77
View File
@@ -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();
}
}
+10 -9
View File
@@ -16,8 +16,9 @@
--- ---
## Requirements ## Requirements
- .NET 8.0 or later - .NET 10.0 or later
- ASP.NET Core - ASP.NET Core
- [Telegrator.Hosting](https://github.com/Rikitav/Telegrator)
--- ---
@@ -37,10 +38,10 @@ using Telegrator.Hosting;
using Telegrator.Hosting.Web; using Telegrator.Hosting.Web;
// Creating builder // Creating builder
TelegramBotWebHostBuilder builder = TelegramBotWebHost.CreateBuilder(new TelegramBotWebOptions() TelegramBotWebHostBuilder builder = TelegramBotWebHost.CreateBuilder(new WebApplicationOptions()
{ {
Args = args, Args = args,
ExceptIntersectingCommandAliases = true ApplicationName = "Telegrator WebApplication example",
}); });
// Register handlers // Register handlers
@@ -61,23 +62,23 @@ telegramBot.Run();
```json ```json
{ {
"TelegramBotClientOptions": { "TelegratorOptions": {
"Token": "YOUR_BOT_TOKEN" "Token": "YOUR_BOT_TOKEN",
"ExceptIntersectingCommandAliases": true
} }
"TelegratorWebOptions": { "WebhookerOptioons": {
"WebhookUri" = "https://you-public-host.ru/bot", "WebhookUri" = "https://you-public-host.ru/bot",
"SecretToken": "MEDIC_GAMING"
"DropPendingUpdates": true "DropPendingUpdates": true
} }
} }
``` ```
- `TelegramBotClientOptions`: Bot token and client settings
--- ---
## Documentation ## 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) - [Getting Started Guide](https://github.com/Rikitav/Telegrator/wiki/Getting-started)
- [Annotation Overview](https://github.com/Rikitav/Telegrator/wiki/Annotation-overview) - [Annotation Overview](https://github.com/Rikitav/Telegrator/wiki/Annotation-overview)
@@ -41,11 +41,8 @@ namespace Telegrator
/// <summary> /// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
/// </summary> /// </summary>
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; IServiceCollection services = builder.Services;
IConfigurationManager configuration = builder.Configuration; IConfigurationManager configuration = builder.Configuration;
+6 -5
View File
@@ -15,7 +15,7 @@
--- ---
## Requirements ## Requirements
- .NET 8.0 or later - .NET 10.0 or later
- [Telegrator](https://github.com/Rikitav/Telegrator) - [Telegrator](https://github.com/Rikitav/Telegrator)
--- ---
@@ -35,10 +35,10 @@ dotnet add package Telegrator.Hosting
using Telegrator.Hosting; using Telegrator.Hosting;
// Creating builder // Creating builder
TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new TelegramBotHostBuilderSettings() TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new HostApplicationBuilderSettings()
{ {
Args = args, Args = args,
ExceptIntersectingCommandAliases = true ApplicationName = "TelegramBotHost example",
}); });
// Registerring handlers // Registerring handlers
@@ -59,8 +59,9 @@ telegramBot.Run();
```json ```json
{ {
"TelegramBotClientOptions": { "TelegratorOptions": {
"Token": "YOUR_BOT_TOKEN" "Token": "YOUR_BOT_TOKEN",
"ExceptIntersectingCommandAliases": true
}, },
"HostOptions": { "HostOptions": {
+1 -4
View File
@@ -48,11 +48,8 @@ public static class HostBuilderExtensions
/// <summary> /// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
/// </summary> /// </summary>
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; IServiceCollection services = builder.Services;
IConfigurationManager configuration = builder.Configuration; IConfigurationManager configuration = builder.Configuration;