cnet 1.7.0
dotnet add package cnet --version 1.7.0
NuGet\Install-Package cnet -Version 1.7.0
<PackageReference Include="cnet" Version="1.7.0" />
<PackageVersion Include="cnet" Version="1.7.0" />
<PackageReference Include="cnet" />
paket add cnet --version 1.7.0
#r "nuget: cnet, 1.7.0"
#:package cnet@1.7.0
#addin nuget:?package=cnet&version=1.7.0
#tool nuget:?package=cnet&version=1.7.0

cnet
Telegram bot toolkit for .NET 9 — strongly typed handlers, built-in flood control and automatic retry, sessions and FSM, media-group aggregation, long polling, and hardened webhooks.
Quick start
var builder = Host.CreateApplicationBuilder(args);
builder.Services
.AddCnet(options => options.BotToken = builder.Configuration["BotToken"]!)
.UseReplayGuard()
.OnCommand("start", async cmd =>
{
var keyboard = Keyboard.Inline()
.Row().Callback("Help", "help").Url("Site", "https://example.com")
.Build();
await cmd.ReplyAsync("<b>Hello!</b>", keyboard);
})
.OnCallback("help", async cb =>
{
await cb.AnswerAsync();
await cb.EditTextAsync("Help text");
})
.OnMessage(async msg =>
{
await msg.TypingAsync();
await msg.ReplyQuotedAsync("Echo: " + msg.Text);
})
.UsePolling();
await builder.Build().RunAsync();
For webhooks, add the cnet.aspnetcore package:
builder.Services.AddCnetWebhook(options =>
{
options.PublicUrl = "https://bot.example.com";
options.Path = "/telegram/webhook";
options.SecretToken = configuration["WebhookSecret"]!;
});
app.MapCnetWebhook();
Highlights
- Typed turns: command, callback, message, and album handlers each receive a dedicated context with exactly the operations that interaction supports
- Automatic retry on 429 (
retry_afterrespected) and transient network errors - Proactive outbound throttle: 30 msg/s global, 1 msg/s per chat, on by default
- Sessions and FSM with
OnState(...)routing and pluggable storage - Media-group aggregation: whole albums arrive as one event
- Inbound per-user rate limiting, replay protection, global error hook
- Class-based handlers with constructor injection
- Bounded update queue with backpressure and graceful shutdown
- Wrappers for every common send and management operation, plus
ctx.Botfor direct IntelliSense access to all 180+ Bot API 10.1 methods (rich messages, guardian bots, gifts, business accounts) with the same retry policy
Documentation
License
Released under the MIT License. Telegram is a trademark of Telegram FZ-LLC; this project is independent and not affiliated with or endorsed by Telegram.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Http (>= 9.0.8)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Options (>= 9.0.8)
- Telegram.Bot (>= 22.10.1.1)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on cnet:
| Package | Downloads |
|---|---|
|
cnet.aspnetcore
ASP.NET Core webhook integration for the cnet Telegram toolkit: secure webhook endpoint with secret-token validation and automatic webhook registration. |
|
|
cnet.metrics
OpenTelemetry-compatible metrics for the cnet Telegram toolkit: update counts, processing latency, and failure counters exposed through a standard System.Diagnostics.Metrics meter. |
|
|
cnet.redis
Redis backing for the cnet Telegram toolkit: durable update queue (Redis Streams), distributed replay protection, and shared session storage — everything a multi-instance bot needs. |
|
|
cnet.testing
Test harness for cnet Telegram bots: drive commands, messages, and callbacks through your real handler pipeline with a fake bot client, and assert on the outgoing requests — no Telegram connection required. |
GitHub repositories
This package is not used by any popular GitHub repositories.