TgBotCommandHandler 0.1.1

dotnet add package TgBotCommandHandler --version 0.1.1                
NuGet\Install-Package TgBotCommandHandler -Version 0.1.1                
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="TgBotCommandHandler" Version="0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TgBotCommandHandler --version 0.1.1                
#r "nuget: TgBotCommandHandler, 0.1.1"                
#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 TgBotCommandHandler as a Cake Addin
#addin nuget:?package=TgBotCommandHandler&version=0.1.1

// Install TgBotCommandHandler as a Cake Tool
#tool nuget:?package=TgBotCommandHandler&version=0.1.1                

TgBotCommandHandler

is a library that provides easy-to-use command handlers for Telegram bots commands from User

If you like this project please give a star and a cup of coffee =)

"Buy Me A Coffee"

Installation

NuGet Badge

To install TgBotCommandHandler, you can use the NuGet package manager in Visual Studio. Simply search for "TgBotCommandHandler" and click "Install".

Alternatively, you can install TgBotCommandHandler using the command line:

Install-Package TgBotCommandHandler

Getting Started

  1. Register your command handler classes using botClient.RegisterCommand<MyCommandHandler> where MyCommandHandler is a subclass of CommandHandler and botClient is an instance of ITelegramBotClient
  2. initialize the botClient.HandleCommands(update) where update is an instance of Telegram.Bot.Types.Update

Example

var botClient = new TelegramBotClient("YOUR_BOT_TOKEN");

botClient.RegisterCommand<MyCommandHandler>();
botClient.InitializeCommands(commandHandler);

botClient.StartReceiving(updateHandler: HandleUpdateAsync,
                pollingErrorHandler: HandlePollingErrorAsync,
                receiverOptions: receiverOptions,
                cancellationToken: cancellationToken);

⚠️ NOTE: do NOT put your Token directly to your source code.

async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
{
    // Only process Message updates: https://core.telegram.org/bots/api#message
    if (update.Message is not { } message)
        return;
    // Only process text messages
    if (message.Text is not { } messageText)
        return;
    await botClient.HandleCommands(update);
}
Command Handlers
public class MyCommandHandler : CommandHandler
{

    // All command methods MUST be async, have a return type of Task, have only a Command  as a parameter,
    // and have the [Command] attribute.
    // The parameter for the [Command] attribute indicates what invokes this method. DO NOT specify a prefix here.
    
    // When a user invokes the /hello command, the bot will respond with "Hello".
    [Command("hello")]
    public async Task HandleHelloCommand(CommandContext context)
    {
        Console.WriteLine("hello command request.");
        await context.RespondAsync("Hello");
    }

    // When a user invokes the /world command, the bot will respond with "World".
    [Command("world")]
    public async Task HandleWorldCommand(CommandContext context)
    {
        Console.WriteLine("world command request.");
        await context.RespondAsync("World");
    }

}
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

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
0.1.1 693 4/11/2023
0.1.0 601 4/2/2023