Tebot 0.3.77-beta

This is a prerelease version of Tebot.
dotnet add package Tebot --version 0.3.77-beta
                    
NuGet\Install-Package Tebot -Version 0.3.77-beta
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tebot" Version="0.3.77-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tebot" Version="0.3.77-beta" />
                    
Directory.Packages.props
<PackageReference Include="Tebot" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tebot --version 0.3.77-beta
                    
#r "nuget: Tebot, 0.3.77-beta"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tebot@0.3.77-beta
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tebot&version=0.3.77-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Tebot&version=0.3.77-beta&prerelease
                    
Install as a Cake Tool

Tebot

NuGet Version

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.md for 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 caption
  • Data - User's persistent state
  • BotClient - Telegram Bot API client
  • currentUpdate - Full Update object
  • Logger - 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed