SKitLs.Bots.Telegram.Core 2.1.3

Prefix Reserved
Additional Details

Delivery System does not send messages due to invalid ParseMode and ReplyToMessageId properties.

There is a newer version of this package available.
See the version list below for details.
dotnet add package SKitLs.Bots.Telegram.Core --version 2.1.3                
NuGet\Install-Package SKitLs.Bots.Telegram.Core -Version 2.1.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="SKitLs.Bots.Telegram.Core" Version="2.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SKitLs.Bots.Telegram.Core --version 2.1.3                
#r "nuget: SKitLs.Bots.Telegram.Core, 2.1.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 SKitLs.Bots.Telegram.Core as a Cake Addin
#addin nuget:?package=SKitLs.Bots.Telegram.Core&version=2.1.3

// Install SKitLs.Bots.Telegram.Core as a Cake Tool
#tool nuget:?package=SKitLs.Bots.Telegram.Core&version=2.1.3                

SKitLs.Bots.Telegram.Core Static Badge GitHub Nuget CodeFactor

The core module of the SKitLs.Bots.Telegram Framework.

First time here? Jump to Quick Start!

Description

SKitLs.Bots.Telegram.Core is a central package of the SKitLs.Bots.Telegram framework, providing essential mechanics for interfacing with the Telegram API. Serving as a wrapper for the Telegram.Bot project, it acts as a core foundation for Telegram bot development.

At the heart of this package lies the BotManager class, designed to streamline the interaction process with server updates and unpack them into strictly typed ICastedUpdate classes. By leveraging the capabilities of BotManager, developers can automate the handling of updates received from the Telegram servers, facilitating the efficient processing of incoming data.

Furthermore, BotManager incorporates a straightforward Inversion of Control (IoC) container, ensuring seamless management and configuration of dependencies within the framework.

SKitLs.Bots.Telegram.Core empowers developers with a reliable and robust foundation to build Telegram bots with ease. Its comprehensive features and well-structured design facilitate the development process, allowing developers to focus on implementing bot logic without the hassle of handling low-level API interactions.

Setup

Requirements

Before running the project, please ensure that you have the following dependencies installed and properly configured in your development environment.

  • Telegram.Bot 19.0.0 or higher
  • SKitLs.Utils.Loggers 1.4.1 or higher
  • SKitLs.Utils.Localizations 2.2.1 or higher
  • SKitLs.Utils.LocalLoggers 1.3.1 or higher

Installation

  1. Using Terminal Command:

    To install the project using the terminal command, follow these steps:

    1. Open the terminal or command prompt.
    2. Run command:
    dotnet add package SKitLs.Bots.Telegram.Core
    
  2. Using NuGet Packages Manager:

    To install the project using the NuGet Packages Manager, perform the following steps:

    1. Open your preferred Integrated Development Environment (IDE) that supports NuGet package management (e.g., Visual Studio).
    2. Create a new project or open an existing one.
    3. Select "Project" > "Manage NuGet Packages"
    4. In the "Browse" tab, search for the project package you want to install.
    5. Click on the "Install" button to add the selected package to your project.
    6. Follow any additional setup instructions or configurations provided in the project's documentation.
  3. Downloading Source Code and Direct Linking:

    To install the project by downloading the source code and directly linking it to your project, adhere to the following steps:

    1. Visit the project repository on GitHub
    2. Click on the "Code" button and select "Download ZIP" to download the project's source code as a zip archive.
    3. Extract the downloaded zip archive to the desired location on your local machine.
    4. Open your existing project or create a new one in your IDE.
    5. Add the downloaded project files to your solution using the "Add Existing Project" option in your IDE's solution explorer.
    6. Reference the project in your solution and ensure any required dependencies are resolved.
    7. Follow any additional setup or configuration instructions provided in the project's documentation.

Please note that each method may have specific requirements or configurations that need to be followed for successful installation. Refer to the project's documentation for any additional steps or considerations.

Do not forget to download and install appropriate localization pack from GitHub.

Usage

Localizations

Framework Core and each of its extensions supports localized debugging. Some of them requires specific language packages. You can find them in GitHub's locals folder.

Place locals in "resources/locals" or update localization path.

BotBuilder.DebugSettings.DebugLanguage = LangKey.EN;
BotBuilder.DebugSettings.UpdateLocalsPath("path/to/data");

Quick Start

static async Task Main(string[] args)
{
    var privateMessages = new DefaultSignedMessageUpdateHandler();
    var privateTexts = new DefaultSignedMessageTextUpdateHandler
    {
        CommandsManager = new DefaultActionManager<SignedMessageTextUpdate>()
    };
    privateTexts.CommandsManager.AddSafely(StartCommand);
    privateMessages.TextMessageUpdateHandler = privateTexts;
   
    ChatDesigner privates = ChatDesigner.NewDesigner()
        .UseMessageHandler(privateMessages);
   
    await BotBuilder.NewBuilder("YOUR_TOKEN")
        .EnablePrivates(privates)
        .Build()
        .Listen();
}

private static DefaultCommand StartCommand => new("start", Do_StartAsync);
private static async Task Do_StartAsync(SignedMessageTextUpdate update)
{
    await update.Owner.DeliveryService.AnswerSenderAsync("Hello, world!", update);
}

Add more Actions

private static DefaultCommand StartCommand => new("start", Do_StartAsync);
private static async Task Do_StartAsync(SignedMessageTextUpdate update)
{
    await update.Owner.DeliveryService.AnswerSenderAsync("Hello, world!", update);
    // OR if certain chat is needed
    await update.Owner.DeliveryService.SendMessageToChatAsync(update.ChatId, "Hello, world!", update);
}
    
private static DefaultCommand ExitInput => new("Exit bot!", Do_ExitAsync);
private static DefaultCommand ExitCommand => new("exit", Do_ExitAsync);
private static async Task Do_ExitAsync(SignedMessageTextUpdate update)
{
    // Access sent message
    DeliveryResponse response = await update.Owner.DeliveryService.AnswerSenderAsync("Exiting...", update);
    TelegramTextMessage message = new("Precess is completed.");
    message.AllowSendingWithoutReply = true;
    if (response.Success)
    {
        // Reply to message
        message.ReplyToMessageId = response.SentMessage.MessageId;
    }
    await update.Owner.DeliveryService.AnswerSenderAsync(message, update);
}

private static DefaultCallback HelloCallback => new("helloCB", Do_HelloAsync);
private static async Task Do_HelloAsync(SignedCallbackUpdate update)
{
    // Acces Telegram.Bot bot instance if necessary
    await update.Owner.Bot.EditMessageTextAsync(update.TriggerMessageId, "Updated Body!")
}

You can use SKitLs.Bots.Telegram.AdvancedMessages package to get better messaging experience.

Use services

  • Add service to bot

    // ...
    await BotBuilder.NewBuilder("YOUR_TOKEN")
        .EnablePrivates(privates)
        .AddServices<ISomeService>(new DefaultSomeService())
        .Build()
        .Listen();
    
  • Resolve one when needed

    private static DefaultCommand StartCommand => new("start", Do_StartAsync);
    private static async Task Do_StartAsync(SignedMessageTextUpdate update)
    {
        var someService = update.Owner.ResolveService<ISomeService>();
        await update.Owner.DeliveryService.AnswerSenderAsync(someService.GetContentFor(update.Text), update);
    }
    

Visit GitHub page for more information.

Contributors

Currently, there are no contributors actively involved in this project. However, our team is eager to welcome contributions from anyone interested in advancing the project's development.

We value every contribution and look forward to collaborating with individuals who share our vision and passion for this endeavor. Your participation will be greatly appreciated in moving the project forward.

Thank you for considering contributing to our project.

License

This project is distributed under the terms of the MIT License.

Copyright (C) SKitLs 2023

Developer contact

For any issues related to the project, please feel free to reach out to us through the project's GitHub page. We welcome bug reports, feedback, and any other inquiries that can help us improve the project.

You can also contact the project owner directly via their GitHub profile at the following link or email: skitlsdev@gmail.com

Your collaboration and support are highly appreciated, and we will do our best to address any concerns or questions promptly and professionally. Thank you for your interest in our project.

Notes

Thank you for choosing our solution for your needs, and we look forward to contributing to your project's success.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 (6)

Showing the top 5 NuGet packages that depend on SKitLs.Bots.Telegram.Core:

Package Downloads
SKitLs.Bots.Telegram.AdvancedMessages

Offers enhanced methods for sending messages in Telegram bots. An extension project built upon the SKitLs.Bots.Telegram.Core Framework.

SKitLs.Bots.Telegram.ArgedInteractions

Provides mechanism for the serialization and deserialization of textual data. An extension project built upon the SKitLs.Bots.Telegram.Core Framework.

SKitLs.Bots.Telegram.PageNavs

Allows to create special navigational menus. An extension project built upon the SKitLs.Bots.Telegram.Core Framework.

SKitLs.Bots.Telegram.Stateful

Enables the segregation of user states. An extension project built upon the SKitLs.Bots.Telegram.Core Framework.

SKitLs.Bots.Telegram.BotProcesses

Provides methods of creating bot processes with advanced textual input mechanics. An extension project built upon the SKitLs.Bots.Telegram.Core Framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

(~) IBuildableMessage : ICloneable support Added
(~) BuildableMessage.Clone() implemented
(~) ITelegramMessage properies' setters Added