SkyNeg.Telegram.BotCore
0.33.0
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.33.0
NuGet\Install-Package SkyNeg.Telegram.BotCore -Version 0.33.0
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.33.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SkyNeg.Telegram.BotCore --version 0.33.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SkyNeg.Telegram.BotCore, 0.33.0"
#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.33.0 // Install SkyNeg.Telegram.BotCore as a Cake Tool #tool nuget:?package=SkyNeg.Telegram.BotCore&version=0.33.0
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:
- Should implement IRequestController interface
- It's constructor may contain dependencies that will be injected with DI (Each Request Controller behaves like a singleton)
- Must contain
Task<RequestResult> ExecuteAsync(BotRequestContext requestContext)
method.ExecuteAsync
method:- Must return
Task<RequestResult>
- Must have first argument of type BotRequestContext
- May contain any number of dependencies, which will be injected during execution using DI. Dependency is injected for each request. We are not limited to singletone dependencies here.
- Must return
- 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(BotRequestContext requestContext, ISampleTransientService transientService) { await _sampleDependencyService.DoWork(requestContext.Request.Text, requestContext.RequestAborted); await transientService.DoWorkAsync(); return RequestResult.Completed; } }
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.2)
- 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.2)
- Microsoft.Extensions.Localization.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
- SkyNeg.Sqlite.RuntimeMigration (>= 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.