Telegram.Bot.AttributeCommands
1.0.3
See the version list below for details.
dotnet add package Telegram.Bot.AttributeCommands --version 1.0.3
NuGet\Install-Package Telegram.Bot.AttributeCommands -Version 1.0.3
<PackageReference Include="Telegram.Bot.AttributeCommands" Version="1.0.3" />
paket add Telegram.Bot.AttributeCommands --version 1.0.3
#r "nuget: Telegram.Bot.AttributeCommands, 1.0.3"
// Install Telegram.Bot.AttributeCommands as a Cake Addin #addin nuget:?package=Telegram.Bot.AttributeCommands&version=1.0.3 // Install Telegram.Bot.AttributeCommands as a Cake Tool #tool nuget:?package=Telegram.Bot.AttributeCommands&version=1.0.3
Telegram.Bot.Telegram.Bot.AttributeCommands Library Documentation
The Telegram.Bot.Telegram.Bot.AttributeCommands
library provides a streamlined approach to managing and executing text, callback, and reply commands for a Telegram bot. The library utilizes custom attributes to mark and categorize methods, simplifying the registration and processing of commands.
Table of Contents
Introduction
The Telegram.Bot.Telegram.Bot.AttributeCommands
library offers a convenient solution for managing and processing various types of commands within a Telegram bot. By leveraging custom attributes, the library organizes text, callback, and reply commands, resulting in a more structured and efficient command handling process.
Getting Started
- Install the
Telegram.Bot.Telegram.Bot.AttributeCommands
library via your preferred package manager. - Import necessary namespaces:
using System;
using System.Reflection;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.AttributeCommands;
using Telegram.Bot.AttributeCommands.Exceptions;
- Create an instance of the
Telegram.Bot.Telegram.Bot.AttributeCommands
class to begin managing your commands.
Usage
Attributes
The Telegram.Bot.AttributeCommands
library includes three custom attributes to mark methods as different types of commands.
TextCommandAttribute
The TextCommandAttribute
is used to identify methods as text commands for your Telegram bot.
[TextCommand("your_text_command")]
public static void YourTextCommandMethod(TelegramBotClient client, Update update)
{
// Your text command logic here
}
CallbackCommandAttribute
The CallbackCommandAttribute
is employed for marking methods as callback commands.
[CallbackCommand("your_callback_command")]
public static void YourCallbackCommandMethod(TelegramBotClient client, Update update)
{
// Your callback command logic here
}
ReplyCommandAttribute
The ReplyCommandAttribute
is used to indicate methods as reply commands.
[ReplyCommand("your_reply_command")]
public static void YourReplyCommandMethod(TelegramBotClient client, Update update)
{
// Your reply command logic here
}
Exceptions
The Telegram.Bot.AttributeCommands
library provides custom exceptions for error handling.
CommandNotFoundException
Thrown when attempting to process a non-existent command.
CommandExistsException
Thrown when trying to register a command with a duplicate name.
Example
using Telegram.Bot;
using Telegram.Bot.Types;
public class YourCommandsClass
{
[TextCommand("start")]
public static void StartCommand(TelegramBotClient client, Update update)
{
// Logic for the start text command
}
[CallbackCommand("button_click")]
public static void ButtonClickCallback(TelegramBotClient client, Update update)
{
// Logic for the button click callback command
}
[ReplyCommand("thanks")]
public static void ThankYouReply(TelegramBotClient client, Update update)
{
// Logic for the thank you reply command
}
}
Exception Handling
When using the Telegram.Bot.AttributeCommands
library, handle exceptions to ensure a smooth user experience. Catch CommandNotFoundException
and CommandExistsException
exceptions as needed.
This comprehensive documentation covers the Telegram.Bot.AttributeCommands
library, including its custom attributes and exceptions. For more detailed information and usage scenarios, refer to the library's source code and comments.
Please note that this documentation is provided for informational purposes and may require adjustments based on the specific implementation of your project.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- Telegram.Bot (>= 19.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.