SkyNeg.Telegram.BotCore 0.35.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SkyNeg.Telegram.BotCore --version 0.35.0
NuGet\Install-Package SkyNeg.Telegram.BotCore -Version 0.35.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.35.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.35.0
#r "nuget: SkyNeg.Telegram.BotCore, 0.35.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.35.0

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

Telegram Bot Service Core library

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

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. Should implement IRequestController interface
    2. It's constructor may contain dependencies that will be injected with DI (Each Request Controller behaves like a singleton)
    3. Must contain Task<RequestResult> ExecuteAsync(BotRequestContext requestContext) method. ExecuteAsync method:
      1. Must return Task<RequestResult>
      2. Must have first argument of type BotRequestContext
      3. 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.
    4. 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 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 70 5/14/2024
0.40.2 71 5/12/2024
0.40.1 73 5/12/2024
0.40.0 75 5/12/2024
0.39.0 97 5/7/2024
0.38.2 100 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