TgBotLib.Core
1.2.7
dotnet add package TgBotLib.Core --version 1.2.7
NuGet\Install-Package TgBotLib.Core -Version 1.2.7
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="TgBotLib.Core" Version="1.2.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TgBotLib.Core" Version="1.2.7" />
<PackageReference Include="TgBotLib.Core" />
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 TgBotLib.Core --version 1.2.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TgBotLib.Core, 1.2.7"
#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 TgBotLib.Core@1.2.7
#: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=TgBotLib.Core&version=1.2.7
#tool nuget:?package=TgBotLib.Core&version=1.2.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Telegram bot lib
Установка
- Установите nuget:
dotnet add package TgBotLib.Core - В Program.cs добавить следующую строку:
builder.Services.AddBotLibCore(options => { options.BotToken = "2065215367:AAEKo4QKE7BmbH7JmUdL57YTPjj7YGeemzA"; options.ExceptionsHandler = new ExceptionsHandler(); // Optional });
Пример
Методы контроллера, помеченные атрибутами из библиотеки, не должны иметь параметров и должны возвращать Task
Пример стандартного контроллера:
public class TestController : BotController
{
private readonly IInlineButtonsGenerationService _buttonsGenerationService;
private readonly IKeyboardButtonsGenerationService _keyboardButtonsGenerationService;
private readonly string[] _sites = ["Google", "Github", "Telegram", "Wikipedia"];
private readonly string[] _siteDescriptions =
[
"Google is a search engine",
"Github is a git repository hosting",
"Telegram is a messenger",
"Wikipedia is an open wiki"
];
public TestController(IInlineButtonsGenerationService buttonsGenerationService, IKeyboardButtonsGenerationService keyboardButtonsGenerationService)
{
_buttonsGenerationService = buttonsGenerationService;
_keyboardButtonsGenerationService = keyboardButtonsGenerationService;
}
[Message("Test")]
[Message(@"Test\d", isPattern: true)]
public Task TestMessage()
{
_keyboardButtonsGenerationService.SetKeyboardButtons("Test", "Test1", "Buttons");
return Client.SendTextMessageAsync(Update.GetChatId(),
"Test message",
replyMarkup: _keyboardButtonsGenerationService.GetButtons());
}
[Callback(nameof(TestCallback))]
[Callback(@"\d", isPattern: true)]
public Task TestCallback()
{
return Client.SendTextMessageAsync(Update.GetChatId(), "Test callback");
}
[Message("Buttons", ignoreCase: true)]
public Task TestWithButtons()
{
_buttonsGenerationService.SetInlineButtons("Test", "2", "3");
return Client.SendTextMessageAsync(Update.GetChatId(),
"Test buttons",
replyMarkup: _buttonsGenerationService.GetButtons());
}
[InlineQuery]
public Task TestInlineQuery()
{
var results = new List<InlineQueryResult>();
var counter = 0;
foreach (var site in _sites.Where(s => s.ToLower().Contains(Update.InlineQuery.Query.ToLower())))
{
results.Add(new InlineQueryResultArticle($"{counter}", site, new InputTextMessageContent(_siteDescriptions[counter])));
counter++;
}
return Client.AnswerInlineQueryAsync(Update.InlineQuery.Id, results);
}
[UnknownMessage]
public Task TestUnknownMessage()
{
return Client.SendTextMessageAsync(Update.GetChatId(), "Hmm... 🤔");
}
[UnknownUpdate]
public Task TestUnknownUpdate()
{
return Client.SendTextMessageAsync(Update.GetChatId(), "HMM... 🤔");
}
}
Пример контроллера с обработкой последовательности:
public class SecondTestController : BotController
{
private readonly IUsersActionsService _usersActionsService;
public SecondTestController(IUsersActionsService usersActionsService)
{
_usersActionsService = usersActionsService;
}
[Message("Init handling")]
public async Task InitHandling()
{
_usersActionsService.HandleUser(BotContext.Update.GetChatId(), nameof(SecondTestController));
await Client.SendTextMessageAsync(BotContext.Update.GetChatId(), "Handling inited");
}
[ActionStep(nameof(SecondTestController), 0)]
public async Task FirstStep()
{
await Client.SendTextMessageAsync(BotContext.Update.GetChatId(), $"First step {BotContext.Update.GetMessageText()}");
}
[ActionStep(nameof(SecondTestController), 1)]
public async Task SecondStep()
{
await Client.SendTextMessageAsync(BotContext.Update.GetChatId(), $"Second step {BotContext.Update.GetMessageText()}");
}
[ActionStep(nameof(SecondTestController), 2)]
public async Task ThirdStep()
{
await Client.SendTextMessageAsync(BotContext.Update.GetChatId(), $"Third step {BotContext.Update.GetMessageText()}");
}
}
Пример обработчика исключений
public class ExceptionsHandler : IExceptionsHandler
{
public Task Handle(Exception ex, ITelegramBotClient botClient, Update update)
{
return botClient.SendTextMessageAsync(update.GetChatId(), ex.ToString());
}
public Task Handle(Exception exception, ITelegramBotClient botClient)
{
return Task.CompletedTask;
}
}
| Product | Versions 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 was computed. 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 was computed. 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.
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- 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.2.7 | 261 | 4/20/2024 |
| 1.2.6 | 223 | 4/13/2024 |
| 1.2.5 | 180 | 4/12/2024 |
| 1.2.4 | 168 | 4/12/2024 |
| 1.2.3 | 146 | 4/12/2024 |
| 1.2.2 | 184 | 4/12/2024 |
| 1.2.1 | 174 | 4/12/2024 |
| 1.2.0 | 164 | 4/12/2024 |
| 1.1.5 | 199 | 4/11/2024 |
| 1.1.4 | 153 | 4/10/2024 |
| 1.1.3 | 179 | 4/8/2024 |
| 1.1.2 | 163 | 4/8/2024 |
| 1.1.1 | 202 | 4/7/2024 |
| 1.1.0 | 168 | 4/7/2024 |
| 1.0.2 | 179 | 4/6/2024 |
| 1.0.1 | 180 | 4/6/2024 |
| 1.0.0 | 171 | 4/6/2024 |