SkyNeg.Telegram.BotCore 0.40.3

dotnet add package SkyNeg.Telegram.BotCore --version 0.40.3
NuGet\Install-Package SkyNeg.Telegram.BotCore -Version 0.40.3
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.40.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SkyNeg.Telegram.BotCore --version 0.40.3
#r "nuget: SkyNeg.Telegram.BotCore, 0.40.3"
#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.40.3

// Install SkyNeg.Telegram.BotCore as a Cake Tool
#tool nuget:?package=SkyNeg.Telegram.BotCore&version=0.40.3

Telegram Bot Service Core library

Framework to build Telegram Bots using Request-Controller pattern with dialogs support

Configuration

Use one of available AddBot extension Dependency Injection methods

AddBot(this IServiceCollection collection, BotOptions botOptions)

or

AddBot(this IServiceCollection collection, IConfiguration botOptionsConfiguration)

Bot Info

To configure response version for /botinfo command implement IBotInfoService interface and inject implementation using dependency injection.

services.AddSingleton<IBotInfoService, BotInfoService>();

Usage

  1. Add Bot Service
    services.AddBot(hostContext.Configuration.GetSection("TelegramBot"));
    
  2. Add Request that defines data model accepted by bot
    1. Request model should implement IRequest interface
    2. 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)
    3. Define public properties for your Request model decorated with RequestPropertyAttribute attribute. These properties can be used to enrich your request with additional data
    4. 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; }
    }
    
  3. Add Request Controller with logic for new command. Each Request Controller class:
    1. Must implement IRequestController interface
    2. It's constructor may contain dependencies that will be injected with DI (Each Request Controller behaves like a singleton)
    3. 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

  1. To request additional information from the user and handle next message from the user by the same controller, return RequestStatus.InProgress status in RequestResult from ExecuteAsync method of your controller
    1. Next message text can be retrieved within the controller request.Text parameter
    2. Additional data (media, etc) can be retrieved from the context.Update parameter
  2. When Dialog is finished, return RequestStatus.Finished status with RequestResult
  3. When some request has a priority over an active dialog, add SuppressDialog RequestFlags to RequestAttribute over the request. Example: CancelRequest
  1. To create a link to another request call Request.ToLink() extension method
  2. To create a callback data for button call Request.ToCallbackData() extension method
Product 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.

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.

Version Downloads Last updated
0.40.3 69 5/14/2024
0.40.2 70 5/12/2024
0.40.1 72 5/12/2024
0.40.0 74 5/12/2024
0.39.0 96 5/7/2024
0.38.2 99 5/6/2024
0.37.0 104 4/16/2024
0.36.0 91 4/16/2024
0.35.0 92 4/15/2024
0.34.0 92 4/15/2024
0.33.0 88 4/15/2024