This project provides a set of C# attributes to facilitate the handling of different types of Telegram bot updates using reflection.
- Inline Query Handling (
InlineAttribute
) - Edited Message Handling (
EditMessageAttribute
) - Command Handling (
CommandHandlerAttribute
) - Callback Query Handling (
CallbackAttribute
) - PreCheckout Query Handling (
PreCheckoutAttribute
) - General Update Handling (
UpdateAttribute
) - Auto-generate telegram client
Ensure you have the required dependencies installed:
dotnet add package yawaflua.Telegram.Net
You can provide dependencies in class from constructor, and after it use it like static
.
public class Example : IUpdatePollingService
{
private static MyCoolService _service; // It should to be static!
public Example(MyCoolService service)
{
_service = service;
}
}
Use the InlineAttribute
to register a method as an inline query handler.
[Inline("example_query")]
public static async Task HandleInlineQuery(ITelegramBotClient bot, InlineQuery query, CancellationToken cancellationToken)
{
// Handle inline query
}
Use the EditMessageAttribute
to register a method as a handler for edited messages.
[EditMessage]
public static async Task HandleEditedMessage(ITelegramBotClient bot, Message message, CancellationToken cancellationToken)
{
// Handle edited message
}
Use the CommandHandlerAttribute
to register a method as a command handler.
You can provide only begin of command text. Like, /start act-
[CommandHandler("/start")]
public static async Task StartCommand(ITelegramBotClient bot, Message message, CancellationToken cancellationToken)
{
// Handle start command
}
Use the CallbackAttribute
to register a method as a callback query handler.
You can provide only begin of callback data text
[Callback("button_click")]
public static async Task HandleCallbackQuery(ITelegramBotClient bot, CallbackQuery query, CancellationToken cancellationToken)
{
// Handle callback query
}
Use the PreCheckoutAttribute
to register a method as a pre-checkout query handler.
[PreCheckout]
public static async Task HandlePreCheckoutQuery(ITelegramBotClient bot, PreCheckoutQuery query, CancellationToken cancellationToken)
{
// Handle pre-checkout query
}
Use the UpdateAttribute
to register a method as a generic update handler.
[Update]
public static async Task HandleUpdate(ITelegramBotClient bot, Update update, CancellationToken cancellationToken)
{
// Handle general update
}
- [ X ] Not working providing dependencies in class constructor and this gives an error.
Try to not use provided dependencies in class. We are should to fix it in v1.0.2.Now just use static variables
This project is open-source and available under the Apache 2.0 License.