SkyNeg.Telegram.BotCore
0.38.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SkyNeg.Telegram.BotCore --version 0.38.2
NuGet\Install-Package SkyNeg.Telegram.BotCore -Version 0.38.2
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="SkyNeg.Telegram.BotCore" Version="0.38.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SkyNeg.Telegram.BotCore --version 0.38.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SkyNeg.Telegram.BotCore, 0.38.2"
#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 SkyNeg.Telegram.BotCore as a Cake Addin #addin nuget:?package=SkyNeg.Telegram.BotCore&version=0.38.2 // Install SkyNeg.Telegram.BotCore as a Cake Tool #tool nuget:?package=SkyNeg.Telegram.BotCore&version=0.38.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Telegram Bot Service Core library
Framework to build Telegram Bots using Request-Controller pattern with dialogs support
Usage
- Add Bot Service
services.AddBot(hostContext.Configuration.GetSection("TelegramBot"));
- Add Request that defines data model accepted by bot
- Request model should implement IRequest interface
- Request model should be decorated with RequestAttribute attribute. Attribute defines command for your request and additional behaviour of your request (for example suppressing dialog flag)
- Define public properties for your Request model decorated with RequestPropertyAttribute attribute. These properties can be used to enrich your request with additional data
- Below is example request. It can be executed from the Telegram using commands:
/myrequest_1
,/myrequest
,/myrequest_42
, etc
[Request("myrequest")] public class MyRequest : IRequest { [RequestProperty(0)] public int MyProperty { get; set; } }
- Add Request Controller with logic for new command. Each Request Controller class:
- Must implement IRequestController interface
- It's constructor may contain dependencies that will be injected with DI (Each Request Controller behaves like a singleton)
- Example:
public class MyRequestController : IRequestController<MyRequest> { private readonly ILogger _logger; private readonly ITelegramBotClient _client; private readonly ISampleDependencyService _sampleDependencyService; public MyRequestController(ILoggerFactory loggerFactory, ITelegramBotClient client, ISampleDependencyService sampleDependencyService) { _sampleDependencyService = sampleDependencyService; _client = client; _logger = loggerFactory?.CreateLogger(GetType()) ?? throw new ArgumentNullException(nameof(loggerFactory)); } public async Task<RequestResult> ExecuteAsync(MyRequest request, RequestContext context, CancellationToken cancellationToken) { await _sampleDependencyService.DoWork(requestContext.Request.Text, requestContext.RequestAborted); return RequestResult.Completed; } }
Dialogs
- To request additional information from the user and handle next message from the user by the same controller, return
RequestStatus.InProgress
status in RequestResult fromExecuteAsync
method of your controller- Next message text can be retrieved within the controller
request.Text
parameter - Additional data (media, etc) can be retrieved from the
context.Update
parameter
- Next message text can be retrieved within the controller
- When Dialog is finished, return
RequestStatus.Finished
status withRequestResult
- When some request has a priority over an active dialog, add
SuppressDialog
RequestFlags toRequestAttribute
over the request. Example: CancelRequest
Links to other Request
- To create a link to another request call Request.ToLink() extension method
- To create a callback data for button call Request.ToCallbackData() extension method
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.EntityFrameworkCore.Sqlite (>= 8.0.4)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.1)
- Microsoft.Extensions.Hosting (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Localization (>= 8.0.4)
- Microsoft.Extensions.Localization.Abstractions (>= 8.0.4)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
- SkyNeg.EntityFramework.Migration (>= 1.1.4)
- SkyNeg.Telegram.Bot.Abstraction (>= 1.0.0)
- Telegram.Bot (>= 19.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SkyNeg.Telegram.BotCore:
Package | Downloads |
---|---|
SkyNeg.Telegram.BotCore.Web
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.