TgBotLib.Core 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package TgBotLib.Core --version 1.1.2
                    
NuGet\Install-Package TgBotLib.Core -Version 1.1.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="TgBotLib.Core" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TgBotLib.Core" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="TgBotLib.Core" />
                    
Project file
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.1.2
                    
#r "nuget: TgBotLib.Core, 1.1.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.
#:package TgBotLib.Core@1.1.2
                    
#: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.1.2
                    
Install as a Cake Addin
#tool nuget:?package=TgBotLib.Core&version=1.1.2
                    
Install as a Cake Tool

Telegram bot lib

NuGet Version GitHub License GitHub Actions Workflow Status

Установка

  1. Установите nuget:
    dotnet add package TgBotLib.Core
    
  2. В Program.cs добавить следующую строку:
    builder.Services.AddBotLibCore("<YOUR_BOT_TOKEN>");
    

Пример

Далее, по аналогии, можно добавить контроллеры

Пример стандартного контроллера:

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(@"Test")]
    [Callback(@"\d", isPattern: true)]
    public Task TestCallback()
    {
        return Client.SendTextMessageAsync(Update.GetChatId(), "Test callback");
    }

    [Message("Buttons")]
    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)
        {
            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()}");
    }
}
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.  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.

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