Tebot 0.2.61

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tebot --version 0.2.61
                    
NuGet\Install-Package Tebot -Version 0.2.61
                    
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.2.61" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tebot" Version="0.2.61" />
                    
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.2.61
                    
#r "nuget: Tebot, 0.2.61"
                    
#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.2.61
                    
#: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.2.61
                    
Install as a Cake Addin
#tool nuget:?package=Tebot&version=0.2.61
                    
Install as a Cake Tool

Tebot

NuGet Version

This is a small wrapper library for Telegram.Bot. With it, you can simplify the creation of complex bot logic. In TebotConsole you can find a example small console app.

Why?

When you try to make telegram bot on Telegram.Bot, you usually have one big method like OnUpdate(Update update, ...) which process every update. And in this method you usually have a lot of if/else, switch and other shit. With this, you method easy can grow up to many lines of code.\n\n But with this libary we can represent user as class instance, and all updates and actions from concrete user will be applyed only to class instance

Base usage

For first, you should create you own class, which derivites from Tebot.Base, for example

public class Bot : Base{
    
}

All class have a thing which we call "State". So, with this we can have class as State machine. Lets create class with 2 states:

public class StateMachine : Base{
    [StateId(State = "/start")]
    public async Task HelloWorld(){
        await Bot.SendTextMessageAsync(UserId, "Hello world");
        NextState = "Bye";
    }
    [StateId(State = "Bye")]
    public async Task ByeWorld(){
        await Bot.SendTextMessageAsync(UserId, "Bye world");
        NextState = "/start";
    }
}

So, what happens here? To get a better representation, we can to look on graph:\n

graph TD;
    HelloWorld-->ByeWorld;
    ByeWorld-->HelloWorld;

In general, when we send message to bot, he execute surrent state. Surrent state defined by NextState variable. To make a new state, we should create new method and add StateId attribute to him.\n\n And, in general, it`s looks like

  1. User send message to bot in telegram app
  2. Invokes HelloWorld() method.(because default value for NextState variable is a /start, but of course we can override this)
  3. Call await Bot.SendTextMessageAsync(UserId, "Hello world");, which send to user Hello world string. UserId in this context is a long variable, defined in Base class and represent actual user account id.
  4. NextState = "Bye"; - we set Bye as next state. After this, method ends.
  5. Now user can send another message to bot.
  6. After we recive new message, Tebot invoke ByeWorld method, because his have StateId attribute with Bye value.
  7. We again send message to user
  8. We set next state to /start etc we return to step 1.

And now we need only to add main method:

static void Main(string[] args)
    {
        var tb = new Tebot.Tebot("6510000000:AAGCKkSY***", typeof(StateMachine), StateLoader.Empty());
        tb.Run();
        Console.ReadKey();
        tb.Stop();
    }

Where first argument is bot token, second - Type to our class, and third - don`t thing about it now.

Going deeper

Dependency Injection

Library support dependency injection. To this, pass IServiceProvider in Tebot constructor. If not set, class will try to create objects by himself, pass to his constructors null value.

Host

It`s recommend to use Microsoft.Extensions.Hosting to create application. Example you can find at here

Commands

Telegram Bots have commands concept, and this library support it. Commands is very simular to states:

[Command("/value")]
public async Task Bebrachka(int abb = 150){
    await Bot.SendTextMessageAsync(UserId, $"value x{abb}");
}

Command methods can have parameters, which will be set from command. For example, if we send to bot /value 200, then abb value will be a 200. If we send only /value, abb will be equal to default value. Now lib can parce only System.Int32, System.Int64, System.Double and System.String.

Override methods

Base class have some methods, which we can override in our class. | Method | Method Description | | ----------- | ----------- | | OnLoad() | Event, when class instance was loaded | | OnInlineQuery() | When update represents InlineQuery | | OnCallback() | When user click on inline button with callback | | OnCreate() | Call once after create this Base instanse by library. | | OnCommand() | Call if user input is command(starts from / | | OnUpdate() | Call after each update with this user | | ProccessUnknownState() | Called when NextState value can`t be matched with state | | OnException() | If in state we have unhandled exception, library call this method |

Product 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 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. 
.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. 
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 682 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