Search Results for

    Show / Hide Table of Contents

    Callback Queries

    Handles Telegram Callback Queries from Inline Keyboard or from other sources
    Query data value used as path to route event to handler

    Adding callback query handler

    Create in your Telegram Module public method with CallbackQueryHandlerAttribute and pass path argument to it without starting and ending /
    You can add dynamic parts with {name:regex} format
    If regex empty then * pattern used

    using TelegramModularFramework.Modules;
    
    public class SampleModule: TelegramModule
    {
        [CallbackQueryHandler("set/{index:*}")]
        public async Task HandleNumber(int index)
        {
            await EditMessageTextAsync($"Number: {index}");
        }
    }
    

    If module in Group then group path added to CallbackQueryHandlerAttribute path

    [Group("sample")]
    public class SampleState: TelegramModule
    {
        [CallbackQueryHandler("test")]
        public async Task Handle()
        {
            await EditMessageTextAsync($"Handle");
        }
    }
    

    Result path is /sample/test

    Arguments

    All dynamic parts from path can be passed to method by its names
    Path query params also parsed and can be passed
    Values converts with TypeReaders

    Sending buttons

    Sending buttons done by sending replay message with replyMarkup in other Handler

    var replyMarkup = new InlineKeyboardMarkup(new []
    {
        InlineKeyboardButton.WithCallbackData("Display name", "/path/to/callback"),      
    });
    
    await ReplyAsync("Select:", replyMarkup: replyMarkup);
    

    Run Mode

    Run mode can be specified with RunModeAttribute
    Sync - Default. Commands executes in order
    Async - Commands executes asynchronously

    Summary

    To add summary use SummaryAttribute

    [Summary("Do things")]
    

    On Callback Executed

    Subscribe to CallbackExecuted event to handle command post execution

    Exceptions

    If callback executed unsuccessfully handle Exception
    Possible exception:

    • UnknownCommand
    • TypeConvertException
    • BaseCommandException
    • CallbackQueryHandlerBadPath
    • @System.Exception
    • Improve this Doc
    ☀
    ☾
    In This Article
    Back to top
    TelegramModularFramework (c) 2022-2022
    ☀
    ☾