Telegrator.Essentials
18.7.2
dotnet add package Telegrator.Essentials --version 18.7.2
NuGet\Install-Package Telegrator.Essentials -Version 18.7.2
<PackageReference Include="Telegrator.Essentials" Version="18.7.2" />
<PackageVersion Include="Telegrator.Essentials" Version="18.7.2" />
<PackageReference Include="Telegrator.Essentials" />
paket add Telegrator.Essentials --version 18.7.2
#r "nuget: Telegrator.Essentials, 18.7.2"
#:package Telegrator.Essentials@18.7.2
#addin nuget:?package=Telegrator.Essentials&version=18.7.2
#tool nuget:?package=Telegrator.Essentials&version=18.7.2
Telegrator.Essentials
A companion library for Telegrator that provides commonly-requested filters, aspects, and extension methods that are intentionally kept out of the core library. It is fully optional and targets netstandard2.0 so it can be used from any Telegrator-supported project. Sort of a playground for Telegrator related features that i dont want to put in Core library.
What is included
- Filter annotations ready to be placed on handlers
- Pre- and post-processors for cross-cutting concerns
- Extension methods for strings, updates, and handler containers
- Continuous chat actions to keep the "typing" indicator alive
Installation
dotnet add package Telegrator.Essentials
Filter Annotations
WelcomeAttribute
Matches /start commands sent in private chats.
[MessageHandler]
[Welcome]
public class StartHandler : MessageHandler
{
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
{
await Reply("Welcome!", cancellationToken: cancellation);
return Ok;
}
}
PrefixedTriggerWordAttribute
Matches messages that start with a configured prefix and an optional trigger word. Useful for custom command prefixes such as !, ., or /.
[MessageHandler]
[PrefixedTriggerWord(Prefixes = ["/", "!"], Words = ["help", "h"], IgnoreCase = true)]
public class HelpHandler : MessageHandler
{
// handles /help, /h, !help, !h
}
CallbackDataFilterAttribute
Matches callback queries by exact data or prefix.
[CallbackQueryHandler]
[CallbackDataFilter("confirm")]
public class ConfirmHandler : CallbackQueryHandler { }
[CallbackQueryHandler]
[CallbackDataFilter("page:", MatchPrefix = true)]
public class PaginationHandler : CallbackQueryHandler { }
PreventDoubleSubmit
Ignores duplicate callback queries from the same user within a timeout window.
[CallbackQueryHandler]
[PreventDoubleSubmit(TimeoutSeconds = 3)]
public class VoteHandler : CallbackQueryHandler { }
Aspects
RateLimitPreprocessor
A pre-processor that enforces a per-user sliding-window rate limit. State is stored in IStateStorage, so the limit is shared across handlers and survives restarts when persistent storage is used.
[MessageHandler]
[BeforeExecution(typeof(MyRateLimit))]
public class HeavyHandler : MessageHandler { }
public class MyRateLimit : RateLimitPreprocessor
{
public override int MaxRequests => 5;
public override int WindowSeconds => 30;
}
AutoDeletePostProcessor
A post-processor that automatically deletes a bot message after a delay. Schedule it from inside the handler:
[MessageHandler]
[AfterExecution(typeof(AutoDeletePostProcessor))]
public class TempMessageHandler : MessageHandler
{
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
{
var sent = await Reply("This message will self-destruct in 5 seconds.", cancellationToken: cancellation);
container.ScheduleAutoDelete(sent, TimeSpan.FromSeconds(5));
return Ok;
}
}
Extension Methods
Update helpers
long? userId = update.GetUserId();
long? chatId = update.GetChatId();
bool isPrivate = update.IsPrivateChat();
String helpers
"hello world".Truncate(10); // "hello worl…"
"a_b".EscapeMarkdownV2(); // "a\\_b"
"<b>".EscapeHtml(); // "<b>"
Continuous Action
Keep the "typing" status (or any other chat action) alive while a long-running handler executes:
[MessageHandler]
public class SlowHandler : MessageHandler
{
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
{
using var typing = container.StartTypingAction(cancellation);
await Task.Delay(TimeSpan.FromSeconds(5), cancellation);
await Reply("Done!", cancellationToken: cancellation);
return Ok;
}
}
Dependency Injection
Current Essentials components are attribute-driven and do not require DI registration. The extension method is provided for future services:
builder.Services.AddTelegratorEssentials();
License
MIT — same as the rest of the Telegrator project.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
- Telegrator (>= 18.7.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.