Tebot 0.3.77-beta
dotnet add package Tebot --version 0.3.77-beta
NuGet\Install-Package Tebot -Version 0.3.77-beta
<PackageReference Include="Tebot" Version="0.3.77-beta" />
<PackageVersion Include="Tebot" Version="0.3.77-beta" />
<PackageReference Include="Tebot" />
paket add Tebot --version 0.3.77-beta
#r "nuget: Tebot, 0.3.77-beta"
#:package Tebot@0.3.77-beta
#addin nuget:?package=Tebot&version=0.3.77-beta&prerelease
#tool nuget:?package=Tebot&version=0.3.77-beta&prerelease
Tebot
Orleans-based wrapper library for Telegram.Bot that simplifies complex bot logic using the State Machine pattern. Each user is represented as a separate Orleans grain with persistent state.
Documentation
- Full Documentation - Complete API reference, examples, and best practices
- AGENTS.md - Quick reference for AI assistants and developers
For AI Assistants: Read
docs/DOCUMENTATION.mdfor complete API documentation before working with this library.
Why?
When building Telegram bots with Telegram.Bot, you typically end up with one large OnUpdate(Update update, ...) method filled with if/else statements and switch cases. This approach quickly becomes unmaintainable as your bot grows.
Tebot solves this by representing each user as a separate class instance (Orleans grain), where all updates and actions for a specific user are isolated to that instance.
Quick Start
Installation
dotnet add package Tebot
1. Define Your State
public class MyBotState : BotState
{
public int Counter { get; set; } = 0;
public string? UserName { get; set; }
}
2. Create Your Bot
public class MyBot : Bot<MyBot, MyBotState>
{
[State("start")]
public async Task Start()
{
Data.Counter++;
await BotClient.SendMessage(ChatId, $"Hello! Message count: {Data.Counter}");
await SaveAsync();
}
[Command("/reset", "Reset counter")]
public async Task Reset()
{
Data.Counter = 0;
await BotClient.SendMessage(ChatId, "Counter reset!");
await SaveAsync();
}
}
3. Configure and Run
var app = TebotHostBuilder.Build<MyBot, MyBotState>(new TebotConfig
{
ConsoleArguments = args,
StorageName = "my-bot-storage",
StateName = "my-bot-state",
ProcessConfigurationManager = (manager) => {
manager.AddJsonFile("config.json");
}
});
app.Build().Run();
4. Configuration File
Create config.json:
{
"botToken": "YOUR_BOT_TOKEN",
"botBaseUrl": "https://api.telegram.org/bot",
"dataStorage": "memory",
"botClusterId": "dev-cluster",
"botServiceId": "my-bot"
}
State Machine Example
public class RegistrationBot : Bot<RegistrationBot, RegistrationState>
{
[Command("/start", "Start registration")]
public async Task Start()
{
await BotClient.SendMessage(ChatId, "What's your name?");
await GoToState("wait_name");
}
[State("wait_name")]
public async Task WaitName()
{
Data.UserName = Text;
await BotClient.SendMessage(ChatId, "How old are you?");
await GoToState("wait_age");
}
[State("wait_age")]
public async Task WaitAge()
{
if (int.TryParse(Text, out int age))
{
Data.Age = age;
await BotClient.SendMessage(ChatId, $"Registration complete!\nName: {Data.UserName}\nAge: {Data.Age}");
await GoToState("start");
}
else
{
await BotClient.SendMessage(ChatId, "Please enter a valid number");
}
}
}
Key Features
- State Machine Pattern: Define states using
[State("name")]attributes - Commands: Register bot commands with
[Command("/cmd", "description")] - Persistent State: Automatic state persistence via Orleans (Memory or PostgreSQL)
- User Isolation: Each user gets their own grain instance
- Scalability: Built on Orleans for horizontal scaling
- Event Hooks: Override methods like
OnMessageReceived(),OnUpdateReceived(), etc.
Storage Options
Memory (Development)
{
"dataStorage": "memory"
}
PostgreSQL (Production)
{
"dataStorage": "adonet",
"botClusterConnectionString": "Host=localhost;Database=orleans;Username=user;Password=pass",
"botClusterInvariant": "Npgsql"
}
Available Properties in Bot Methods
ChatId- Current chat ID (long)Text- Message text or captionData- User's persistent stateBotClient- Telegram Bot API clientcurrentUpdate- Full Update objectLogger- ILogger instance
Override Methods
protected override async Task OnMessageReceived(Message message)
{
// Called for every message
}
protected override async Task OnUpdateReceived(Update update)
{
// Called for every update
}
protected override async Task OnInlineQueryRequest(InlineQuery inlineQuery)
{
// Handle inline queries
}
More Examples
See TebotAsHost/Program.cs for a complete working example.
For detailed documentation, examples, and best practices, see docs/DOCUMENTATION.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 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 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.Hosting (>= 10.0.3)
- Microsoft.Orleans.Clustering.AdoNet (>= 10.0.1)
- Microsoft.Orleans.Core.Abstractions (>= 10.0.1)
- Microsoft.Orleans.Persistence.AdoNet (>= 10.0.1)
- Microsoft.Orleans.Server (>= 10.0.1)
- Telegram.Bot (>= 22.9.5.3)
-
net8.0
- Microsoft.Extensions.Hosting (>= 10.0.3)
- Microsoft.Orleans.Clustering.AdoNet (>= 10.0.1)
- Microsoft.Orleans.Core.Abstractions (>= 10.0.1)
- Microsoft.Orleans.Persistence.AdoNet (>= 10.0.1)
- Microsoft.Orleans.Server (>= 10.0.1)
- System.Threading.Channels (>= 10.0.3)
- Telegram.Bot (>= 22.9.5.3)
-
net9.0
- Microsoft.Extensions.Hosting (>= 10.0.3)
- Microsoft.Orleans.Clustering.AdoNet (>= 10.0.1)
- Microsoft.Orleans.Core.Abstractions (>= 10.0.1)
- Microsoft.Orleans.Persistence.AdoNet (>= 10.0.1)
- Microsoft.Orleans.Server (>= 10.0.1)
- System.Threading.Channels (>= 10.0.3)
- Telegram.Bot (>= 22.9.5.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.3.77-beta | 93 | 4/9/2026 |
| 0.3.76-beta | 97 | 4/9/2026 |
| 0.3.75-beta | 104 | 4/9/2026 |
| 0.3.74-beta | 96 | 3/9/2026 |
| 0.3.73-beta | 101 | 3/9/2026 |
| 0.3.72-beta | 107 | 3/9/2026 |
| 0.3.71-beta | 94 | 3/8/2026 |
| 0.3.70-beta | 107 | 3/8/2026 |
| 0.3.69-beta | 101 | 3/7/2026 |
| 0.2.65 | 587 | 2/26/2026 |
| 0.2.64 | 571 | 2/26/2026 |
| 0.2.63 | 574 | 2/26/2026 |
| 0.2.62 | 688 | 1/3/2026 |
| 0.2.61 | 637 | 1/3/2026 |
| 0.2.60 | 637 | 1/3/2026 |
| 0.2.58 | 641 | 1/3/2026 |
| 0.2.57 | 640 | 1/3/2026 |
| 0.2.56 | 639 | 12/31/2025 |
| 0.2.55 | 932 | 11/21/2025 |
| 0.2.54 | 898 | 11/21/2025 |