Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4b14751c8d | |||
| 3fe0cc3b7c | |||
| ff2060e250 | |||
| 7df9e1e952 | |||
| a3fd6a6007 |
@@ -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)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,11 +3,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Telegram.Bot;
|
|
||||||
using Telegrator;
|
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
using Telegrator.Providers;
|
|
||||||
|
|
||||||
#pragma warning disable IDE0001
|
#pragma warning disable IDE0001
|
||||||
namespace Telegrator.Hosting.Web
|
namespace Telegrator.Hosting.Web
|
||||||
@@ -46,7 +42,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 +56,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>
|
||||||
|
|||||||
@@ -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
|
## 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 = "TelegramBotWebHost example",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register handlers
|
// Register handlers
|
||||||
@@ -57,27 +58,59 @@ telegramBot.Run();
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Application integration Example
|
||||||
|
|
||||||
|
**Program.cs (ASP.NET Core):**
|
||||||
|
```csharp
|
||||||
|
using Telegrator.Hosting;
|
||||||
|
using Telegrator.Hosting.Web;
|
||||||
|
|
||||||
|
// Creating builder
|
||||||
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(new WebApplicationOptions()
|
||||||
|
{
|
||||||
|
Args = args,
|
||||||
|
ApplicationName = "WebApplication example",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Adding Telegrator
|
||||||
|
builder.AddTelegratorWeb();
|
||||||
|
|
||||||
|
// Register handlers
|
||||||
|
builder.Handlers.CollectHandlersAssemblyWide();
|
||||||
|
|
||||||
|
// Register your services
|
||||||
|
builder.Services.AddSingleton<IMyService, MyService>();
|
||||||
|
|
||||||
|
// Building and running application
|
||||||
|
builder.Build()
|
||||||
|
.UseTelegratorWeb()
|
||||||
|
.SetBotCommands();
|
||||||
|
.Run();
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Configuration (appsettings.json)
|
## Configuration (appsettings.json)
|
||||||
|
|
||||||
```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)
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
|
|
||||||
<Title>Telegrator.Hosting.Web</Title>
|
<Title>Telegrator.Hosting.Web</Title>
|
||||||
<Version>1.16.0</Version>
|
<Version>1.16.1</Version>
|
||||||
<Authors>Rikitav Tim4ik</Authors>
|
<Authors>Rikitav Tim4ik</Authors>
|
||||||
<Company>Rikitav Tim4ik</Company>
|
<Company>Rikitav Tim4ik</Company>
|
||||||
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
||||||
@@ -26,21 +26,18 @@
|
|||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="..\..\LICENSE" Pack="True" PackagePath="\" />
|
|
||||||
<None Include="..\..\README.md" Pack="True" PackagePath="\" />
|
|
||||||
<None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Telegrator.Hosting\Telegrator.Hosting.csproj" />
|
<ProjectReference Include="..\Telegrator.Hosting\Telegrator.Hosting.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
<PackageReference Include="Telegram.Bot.AspNetCore" Version="22.5.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Telegram.Bot.AspNetCore" Version="22.5.0" />
|
<None Include=".\README.md" Pack="True" PackagePath="\" />
|
||||||
|
<None Include="..\..\LICENSE" Pack="True" PackagePath="\" />
|
||||||
|
<None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace Telegrator.Hosting
|
|||||||
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
||||||
_settings = settings ?? new HostApplicationBuilderSettings();
|
_settings = settings ?? new HostApplicationBuilderSettings();
|
||||||
|
|
||||||
_innerBuilder.AddTelegrator(_settings);
|
_innerBuilder.AddTelegrator();
|
||||||
_innerBuilder.Logging.ClearProviders();
|
_innerBuilder.Logging.ClearProviders();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ namespace Telegrator.Hosting
|
|||||||
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
||||||
_settings = settings ?? new HostApplicationBuilderSettings();
|
_settings = settings ?? new HostApplicationBuilderSettings();
|
||||||
|
|
||||||
_innerBuilder.AddTelegrator(_settings, null, handlers);
|
_innerBuilder.AddTelegrator(null, handlers);
|
||||||
_innerBuilder.Logging.ClearProviders();
|
_innerBuilder.Logging.ClearProviders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -55,12 +55,42 @@ telegramBot.Run();
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Application integration Example
|
||||||
|
|
||||||
|
**Program.cs:**
|
||||||
|
```csharp
|
||||||
|
using Telegrator.Hosting;
|
||||||
|
|
||||||
|
// Creating builder
|
||||||
|
HostApplicationBuilder builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings()
|
||||||
|
{
|
||||||
|
Args = args,
|
||||||
|
ApplicationName = "Host example",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Adding Telegrator
|
||||||
|
builder.AddTelegrator();
|
||||||
|
|
||||||
|
// Registerring handlers (extension)
|
||||||
|
builder.Handlers.CollectHandlersAssemblyWide();
|
||||||
|
|
||||||
|
// Building and running application
|
||||||
|
builder.Build()
|
||||||
|
.UseTelegrator()
|
||||||
|
.SetBotCommands()
|
||||||
|
.Run();
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Configuration (appsettings.json)
|
## Configuration (appsettings.json)
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"TelegramBotClientOptions": {
|
"TelegratorOptions": {
|
||||||
"Token": "YOUR_BOT_TOKEN"
|
"Token": "YOUR_BOT_TOKEN",
|
||||||
|
"ExceptIntersectingCommandAliases": true
|
||||||
},
|
},
|
||||||
|
|
||||||
"HostOptions": {
|
"HostOptions": {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
|
|
||||||
<Title>Telegrator.Hosting</Title>
|
<Title>Telegrator.Hosting</Title>
|
||||||
<Version>1.16.0</Version>
|
<Version>1.16.1</Version>
|
||||||
<Authors>Rikitav Tim4ik</Authors>
|
<Authors>Rikitav Tim4ik</Authors>
|
||||||
<Company>Rikitav Tim4ik</Company>
|
<Company>Rikitav Tim4ik</Company>
|
||||||
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
||||||
@@ -26,19 +26,19 @@
|
|||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Telegrator\Telegrator.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.3" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.3" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.3" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include=".\README.md" Pack="True" PackagePath="\" />
|
||||||
<None Include="..\..\LICENSE" Pack="True" PackagePath="\" />
|
<None Include="..\..\LICENSE" Pack="True" PackagePath="\" />
|
||||||
<None Include="..\..\README.md" Pack="True" PackagePath="\" />
|
|
||||||
<None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" />
|
<None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\Telegrator\Telegrator.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Core;
|
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ namespace Telegrator.Mediation
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>A task representing the asynchronous update handling operation.</returns>
|
/// <returns>A task representing the asynchronous update handling operation.</returns>
|
||||||
public virtual async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
public virtual async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_ = HandleUpdateAsyncInternal(botClient, update, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleUpdateAsyncInternal(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// Logging
|
// Logging
|
||||||
LogUpdate(update);
|
LogUpdate(update);
|
||||||
@@ -135,7 +140,28 @@ namespace Telegrator.Mediation
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Queuing reagular handlers for execution
|
// Queuing reagular handlers for execution
|
||||||
await HandlersPool.Enqueue(GetHandlers(HandlersProvider, botClient, update, cancellationToken));
|
foreach (DescribedHandlerDescriptor handlerInfo in GetHandlers(HandlersProvider, botClient, update, cancellationToken))
|
||||||
|
{
|
||||||
|
if (lastResult?.NextType != null)
|
||||||
|
{
|
||||||
|
if (lastResult.NextType != handlerInfo.From.HandlerType)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enqueuing found handlers
|
||||||
|
await HandlersPool.Enqueue(handlerInfo);
|
||||||
|
await handlerInfo.AwaitResult(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
lastResult = handlerInfo.Result;
|
||||||
|
if (lastResult == null)
|
||||||
|
break; // Smth went horribly wrong, better to stop routing
|
||||||
|
|
||||||
|
if (lastResult != null && !lastResult.RouteNext)
|
||||||
|
break;
|
||||||
|
|
||||||
|
TelegratorLogging.LogTrace("Handler '{0}' requested route continuation (Update {1})", handlerInfo.DisplayString, handlerInfo.HandlingUpdate.Id);
|
||||||
|
}
|
||||||
|
|
||||||
TelegratorLogging.LogTrace("Receiving Update ({0}) finished", update.Id);
|
TelegratorLogging.LogTrace("Receiving Update ({0}) finished", update.Id);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
|
|
||||||
<Title>Telegrator : Telegram.Bot mediator framework</Title>
|
<Title>Telegrator : Telegram.Bot mediator framework</Title>
|
||||||
<Version>1.16.0</Version>
|
<Version>1.16.1</Version>
|
||||||
<Authors>Rikitav Tim4ik</Authors>
|
<Authors>Rikitav Tim4ik</Authors>
|
||||||
<Company>Rikitav Tim4ik</Company>
|
<Company>Rikitav Tim4ik</Company>
|
||||||
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
||||||
|
|||||||
Reference in New Issue
Block a user