TelegramBot.NET
1.0.29
dotnet add package TelegramBot.NET --version 1.0.29
NuGet\Install-Package TelegramBot.NET -Version 1.0.29
<PackageReference Include="TelegramBot.NET" Version="1.0.29" />
paket add TelegramBot.NET --version 1.0.29
#r "nuget: TelegramBot.NET, 1.0.29"
// Install TelegramBot.NET as a Cake Addin #addin nuget:?package=TelegramBot.NET&version=1.0.29 // Install TelegramBot.NET as a Cake Tool #tool nuget:?package=TelegramBot.NET&version=1.0.29
<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
- 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();
}
- Add your API key from BotFather to
appsettings.json
file, key isTelegramBotToken
:
{
"TelegramBotToken": "YOUR_API_TOKEN"
}
or use command line arguments:
./TelegramBot.Console TelegramBotToken=YOUR_API_TOKEN
- 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!");
}
}
- 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 ofBotBuilder
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - 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
Product | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.Configuration (>= 9.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 9.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 9.0.0)
- Microsoft.Extensions.Configuration.Json (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 9.0.0)
- Microsoft.Extensions.Logging.Console (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
- Telegram.Bot (>= 22.0.2)
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.29 | 114 | 12/15/2024 |
1.0.28 | 118 | 11/16/2024 |
1.0.27 | 97 | 10/4/2024 |
1.0.26 | 128 | 9/24/2024 |
1.0.25 | 93 | 9/24/2024 |
1.0.24 | 119 | 9/16/2024 |
1.0.23 | 145 | 8/14/2024 |
1.0.22 | 118 | 8/14/2024 |
1.0.21 | 115 | 8/14/2024 |
1.0.20 | 117 | 8/14/2024 |
1.0.19 | 114 | 8/14/2024 |
1.0.18 | 116 | 8/10/2024 |
1.0.17 | 120 | 8/10/2024 |
1.0.16 | 117 | 8/10/2024 |
1.0.15 | 66 | 8/5/2024 |
1.0.14 | 65 | 8/3/2024 |
1.0.13 | 69 | 8/3/2024 |
1.0.12 | 77 | 8/2/2024 |
1.0.11 | 78 | 8/2/2024 |
1.0.10 | 65 | 7/31/2024 |
1.0.9 | 83 | 7/28/2024 |
1.0.8 | 112 | 7/16/2024 |
1.0.7 | 101 | 7/16/2024 |
1.0.6 | 94 | 7/16/2024 |
1.0.5 | 100 | 7/15/2024 |
1.0.4 | 118 | 7/10/2024 |
1.0.3 | 102 | 7/10/2024 |
1.0.2 | 101 | 7/9/2024 |
1.0.1 | 110 | 7/5/2024 |
0.10.1 | 103 | 7/5/2024 |
0.10.0 | 99 | 7/5/2024 |
0.9.1 | 107 | 7/5/2024 |
0.9.0 | 93 | 7/5/2024 |
0.8.0 | 103 | 7/5/2024 |
0.7.0 | 112 | 7/5/2024 |
0.6.0 | 93 | 7/5/2024 |
0.5.0 | 109 | 7/5/2024 |
0.4.0 | 98 | 7/5/2024 |
0.3.0 | 95 | 7/5/2024 |
0.2.1 | 100 | 7/5/2024 |
0.2.0 | 111 | 7/5/2024 |