TelegramBot.NET 1.0.27

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

// Install TelegramBot.NET as a Cake Tool
#tool nuget:?package=TelegramBot.NET&version=1.0.27                

GitHub Nuget Static Badge GitHub Actions Workflow Status NuGet version (TelegramBot.NET) CodeFactor GitHub repo size

<a id="readme-top"></a>

TelegramBot.NET

Ready-to-use .NET Standard library for convenient development of Telegram bots.

Purposes

Many people know the ASP.NET Core platform and its convenience for developing web API applications.

Now you can see the same pattern in Telegram Bot API.

You can find usage examples in the TelegramBot.ConsoleTest project.

You can find Simple Cafe Market example in this controller sample.

Getting Started

Start by importing the library into your project

dotnet add package TelegramBot.NET

  1. Implement simple handler in your Program.cs
static void Main(string[] args)
{
    BotBuilder builder = new BotBuilder(args)
        .UseApiKey(x => x.FromConfiguration());

    var app = builder.Build();
    app.MapControllers();
    app.Run();
}
  1. Add your API key from BotFather to appsettings.json file, key is TelegramBotToken:
{
  "TelegramBotToken": "YOUR_API_TOKEN"
}

or use command line arguments:

./TelegramBot.Console TelegramBotToken=YOUR_API_TOKEN
  1. Implement controller, in this sample - for handling /start command:
public class CommandController(ILogger<CommandController> _logger) : BotControllerBase
{
    [TextCommand("/start")]
    public IActionResult HandleStartAsync()
    {
        _logger.LogInformation("Start command received.");
        return Text("Hello!");
    }
}
  1. Run application - and see result:
info: TelegramBot.BotApp[0]
      Bot started - receiving updates.
info: TelegramBot.ConsoleTest.Controllers.HomeController[0]
      Start command received.

<p align="right"><a href="#readme-top">back to top</a></p>

Features

  • Dependency Injection - use Services property of BotBuilder to add services:
builder.Services.AddDbContext<AppDbContext>(x => x.UseNpgsql(connectionString));
builder.Services.AddScoped<ISomeHandler, Handler>();
  • Send response to client - use BotControllerBase methods - Inline, Text, MarkDown:
[BotCommand("/start")]
public async Task<IActionResult> HandleStartAsync()
{
    string prompt = await _dbContext.Translations.GetTranslationAsync("WelcomePrompt", Language.English);
    InlineKeyboardMarkup keyboard = new KeyboardBuilder()
        .WithColumns(2)
        .AddButton("🇺🇸 English", "/language/en")
        .AddButton("🇷🇺 Русский", "/language/ru")
        .AddButton("🇪🇸 Español", "/language/es")
        .AddButton("🇺🇦 Українська", "/language/uk")
        .Build();
    return Inline(prompt, keyboard);
    // or
    return Text("Hello, it's me!");
    // or
    return Markdown("Okay, click [this](https://example.com) link");
}

<p align="right"><a href="#readme-top">back to top</a></p>

Roadmap

  • Add command handlers
  • Add response types:
    • Text
    • Inline
    • Markdown
    • Image
    • Video
    • Delete
    • Redirect
  • Implement language dictionary service
  • Implement router for inline query
  • Inject user model in base controller
  • Add user state service

See the open issues for a full list of proposed features (and known issues).

<p align="right"><a href="#readme-top">back to top</a></p>

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

<p align="right"><a href="#readme-top">back to top</a></p>

License

Distributed under the MIT License. See LICENSE.md for more information.

Contact

E-Mail

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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
1.0.28 89 11/16/2024
1.0.27 96 10/4/2024
1.0.26 120 9/24/2024
1.0.25 88 9/24/2024
1.0.24 116 9/16/2024
1.0.23 140 8/14/2024
1.0.22 113 8/14/2024
1.0.21 112 8/14/2024
1.0.20 114 8/14/2024
1.0.19 111 8/14/2024
1.0.18 111 8/10/2024
1.0.17 115 8/10/2024
1.0.16 110 8/10/2024
1.0.15 62 8/5/2024
1.0.14 60 8/3/2024
1.0.13 66 8/3/2024
1.0.12 74 8/2/2024
1.0.11 75 8/2/2024
1.0.10 60 7/31/2024
1.0.9 78 7/28/2024
1.0.8 109 7/16/2024
1.0.7 96 7/16/2024
1.0.6 89 7/16/2024
1.0.5 93 7/15/2024
1.0.4 111 7/10/2024
1.0.3 99 7/10/2024
1.0.2 99 7/9/2024
1.0.1 105 7/5/2024
0.10.1 100 7/5/2024
0.10.0 96 7/5/2024
0.9.1 102 7/5/2024
0.9.0 88 7/5/2024
0.8.0 100 7/5/2024
0.7.0 109 7/5/2024
0.6.0 90 7/5/2024
0.5.0 104 7/5/2024
0.4.0 93 7/5/2024
0.3.0 90 7/5/2024
0.2.1 97 7/5/2024
0.2.0 106 7/5/2024