Updated readmes
This commit is contained in:
@@ -55,7 +55,7 @@ using Telegrator.Annotations;
|
||||
[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);
|
||||
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<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellation)
|
||||
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
|
||||
{
|
||||
await Responce("Welcome!", cancellationToken: cancellation);
|
||||
return Result.Ok();
|
||||
@@ -95,10 +95,10 @@ bot.Handlers.AddHandler<StartCommandHandler>();
|
||||
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<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellation)
|
||||
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
|
||||
{
|
||||
container.CreateNumericState();
|
||||
container.ForwardNumericState();
|
||||
@@ -126,7 +126,7 @@ bot.Handlers.AddHandler<StateKeepFirst>();
|
||||
## 📚 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)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -41,11 +41,8 @@ namespace Telegrator
|
||||
/// <summary>
|
||||
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||
/// </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;
|
||||
IConfigurationManager configuration = builder.Configuration;
|
||||
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -48,11 +48,8 @@ public static class HostBuilderExtensions
|
||||
/// <summary>
|
||||
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||
/// </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;
|
||||
IConfigurationManager configuration = builder.Configuration;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user