TelegramBot.NET
1.0.27
dotnet add package TelegramBot.NET --version 1.0.27
NuGet\Install-Package TelegramBot.NET -Version 1.0.27
<PackageReference Include="TelegramBot.NET" Version="1.0.27" />
paket add TelegramBot.NET --version 1.0.27
#r "nuget: TelegramBot.NET, 1.0.27"
// 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
<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 (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 8.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 8.0.0)
- Microsoft.Extensions.Configuration.Json (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- Microsoft.Extensions.Logging.Console (>= 8.0.0)
- System.Text.Json (>= 8.0.4)
- Telegram.Bot (>= 19.0.0)
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.27 | 88 | 10/4/2024 |
1.0.26 | 116 | 9/24/2024 |
1.0.25 | 84 | 9/24/2024 |
1.0.24 | 112 | 9/16/2024 |
1.0.23 | 136 | 8/14/2024 |
1.0.22 | 109 | 8/14/2024 |
1.0.21 | 108 | 8/14/2024 |
1.0.20 | 110 | 8/14/2024 |
1.0.19 | 107 | 8/14/2024 |
1.0.18 | 107 | 8/10/2024 |
1.0.17 | 111 | 8/10/2024 |
1.0.16 | 106 | 8/10/2024 |
1.0.15 | 58 | 8/5/2024 |
1.0.14 | 56 | 8/3/2024 |
1.0.13 | 62 | 8/3/2024 |
1.0.12 | 70 | 8/2/2024 |
1.0.11 | 70 | 8/2/2024 |
1.0.10 | 55 | 7/31/2024 |
1.0.9 | 73 | 7/28/2024 |
1.0.8 | 104 | 7/16/2024 |
1.0.7 | 91 | 7/16/2024 |
1.0.6 | 84 | 7/16/2024 |
1.0.5 | 88 | 7/15/2024 |
1.0.4 | 106 | 7/10/2024 |
1.0.3 | 94 | 7/10/2024 |
1.0.2 | 94 | 7/9/2024 |
1.0.1 | 100 | 7/5/2024 |
0.10.1 | 95 | 7/5/2024 |
0.10.0 | 91 | 7/5/2024 |
0.9.1 | 97 | 7/5/2024 |
0.9.0 | 83 | 7/5/2024 |
0.8.0 | 96 | 7/5/2024 |
0.7.0 | 105 | 7/5/2024 |
0.6.0 | 86 | 7/5/2024 |
0.5.0 | 100 | 7/5/2024 |
0.4.0 | 89 | 7/5/2024 |
0.3.0 | 86 | 7/5/2024 |
0.2.1 | 93 | 7/5/2024 |
0.2.0 | 102 | 7/5/2024 |