Telegrator has unsafe and invalid documentation parts #6

Closed
opened 2026-03-06 09:35:25 +00:00 by TheMakarik · 1 comment
TheMakarik commented 2026-03-06 09:35:25 +00:00 (Migrated from github.com)

Telegrator.Hosting.Web gets and example of invalid JSON

{
  "TelegramBotClientOptions": {
    "Token": "YOUR_BOT_TOKEN"
  }

  "TelegratorWebOptions": {
    "WebhookUri" = "https://you-public-host.ru/bot",
    "DropPendingUpdates": true
  }
}

WebhookUri must use colon instead of equal
And another documentation problem in the filters:

public class DatabaseUserFilterAttribute : FilterAnnotation<Message>
{
    public override bool CanPass(FilterExecutionContext<Message> context)
    {
        // Cast to HostedTelegramBotInfo to access services
        if (context.BotInfo is not HostedTelegramBotInfo botInfo)
            return false;

        // Access DI container
        var dbContext = botInfo.Services.GetRequiredService<UsersDbContext>();
        var configuration = botInfo.Services.GetRequiredService<IConfiguration>();
        
        // Use services in filter logic
        var user = dbContext.Users.FirstOrDefault(u => u.TelegramId == context.Input.From?.Id);
        return user?.IsActive == true;
    }
}

This class is unsafe. DbContext is scoped, so if ValidateOnScope is true, exception will be thrown, or memory leak will be occured (if false). Please consider using IDbContextFactory or create scope.

Telegrator.Hosting.Web gets and example of invalid JSON ```json { "TelegramBotClientOptions": { "Token": "YOUR_BOT_TOKEN" } "TelegratorWebOptions": { "WebhookUri" = "https://you-public-host.ru/bot", "DropPendingUpdates": true } } ``` WebhookUri must use colon instead of equal And another documentation problem in the filters: ```cs public class DatabaseUserFilterAttribute : FilterAnnotation<Message> { public override bool CanPass(FilterExecutionContext<Message> context) { // Cast to HostedTelegramBotInfo to access services if (context.BotInfo is not HostedTelegramBotInfo botInfo) return false; // Access DI container var dbContext = botInfo.Services.GetRequiredService<UsersDbContext>(); var configuration = botInfo.Services.GetRequiredService<IConfiguration>(); // Use services in filter logic var user = dbContext.Users.FirstOrDefault(u => u.TelegramId == context.Input.From?.Id); return user?.IsActive == true; } } ``` This class is unsafe. DbContext is scoped, so if [ValidateOnScope](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.serviceprovideroptions.validatescopes?view=net-10.0-pp) is true, exception will be thrown, or memory leak will be occured (if false). Please consider using [IDbContextFactory](https://learn.microsoft.com/ru-ru/dotnet/api/microsoft.entityframeworkcore.idbcontextfactory-1?view=efcore-9.0) or create scope.
Rikitav commented 2026-03-07 19:41:10 +00:00 (Migrated from github.com)

Fixed

Fixed
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rikitav/Telegrator#6