2025-07-28 20:35:48 +04:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Telegram.Bot;
|
2026-03-06 23:19:24 +04:00
|
|
|
using Telegrator;
|
|
|
|
|
using Telegrator.Core;
|
|
|
|
|
using Telegrator.Providers;
|
2025-07-24 23:19:59 +04:00
|
|
|
|
2025-07-28 20:35:48 +04:00
|
|
|
#pragma warning disable IDE0001
|
2025-07-24 23:19:59 +04:00
|
|
|
namespace Telegrator.Hosting.Web
|
|
|
|
|
{
|
2025-07-28 20:35:48 +04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a web hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TelegramBotWebHostBuilder : ITelegramBotHostBuilder
|
2025-07-24 23:19:59 +04:00
|
|
|
{
|
2025-07-28 20:35:48 +04:00
|
|
|
private readonly WebApplicationBuilder _innerBuilder;
|
|
|
|
|
private readonly TelegramBotWebOptions _settings;
|
2025-08-19 04:33:02 +04:00
|
|
|
private readonly IHandlersCollection _handlers;
|
2025-07-24 23:19:59 +04:00
|
|
|
|
2025-07-28 20:35:48 +04:00
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IHandlersCollection Handlers => _handlers;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IConfigurationManager Configuration => _innerBuilder.Configuration;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public ILoggingBuilder Logging => _innerBuilder.Logging;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IServiceCollection Services => _innerBuilder.Services;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IHostEnvironment Environment => _innerBuilder.Environment;
|
|
|
|
|
|
2025-08-19 04:33:02 +04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="TelegramBotWebHostBuilder"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="webApplicationBuilder"></param>
|
|
|
|
|
/// <param name="settings"></param>
|
|
|
|
|
public TelegramBotWebHostBuilder(WebApplicationBuilder webApplicationBuilder, TelegramBotWebOptions settings)
|
2025-07-28 20:35:48 +04:00
|
|
|
{
|
2025-08-19 04:33:02 +04:00
|
|
|
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
|
2025-07-28 20:35:48 +04:00
|
|
|
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
|
|
|
|
_handlers = new HostHandlersCollection(Services, _settings);
|
2026-03-07 00:17:31 +04:00
|
|
|
|
|
|
|
|
_innerBuilder.AddTelegratorWeb(settings);
|
2025-07-28 20:35:48 +04:00
|
|
|
}
|
|
|
|
|
|
2025-08-19 04:33:02 +04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="TelegramBotWebHostBuilder"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="webApplicationBuilder"></param>
|
|
|
|
|
/// <param name="handlers"></param>
|
|
|
|
|
/// <param name="settings"></param>
|
|
|
|
|
public TelegramBotWebHostBuilder(WebApplicationBuilder webApplicationBuilder, TelegramBotWebOptions settings, IHandlersCollection handlers)
|
|
|
|
|
{
|
|
|
|
|
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
|
|
|
|
|
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
|
|
|
|
_handlers = handlers ?? throw new ArgumentNullException(nameof(settings));
|
2026-03-06 20:49:32 +04:00
|
|
|
|
2026-03-07 00:17:31 +04:00
|
|
|
_innerBuilder.AddTelegratorWeb(settings, handlers);
|
2025-08-19 04:33:02 +04:00
|
|
|
}
|
|
|
|
|
|
2025-07-28 20:35:48 +04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Builds the host.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public TelegramBotWebHost Build()
|
|
|
|
|
{
|
2026-03-07 00:17:31 +04:00
|
|
|
return new TelegramBotWebHost(_innerBuilder);
|
2025-07-28 20:35:48 +04:00
|
|
|
}
|
2025-07-24 23:19:59 +04:00
|
|
|
}
|
|
|
|
|
}
|