Search Results for

    Show / Hide Table of Contents

    States

    If previous handler calls @TelegramModularFramework.Modules.TelegramModule.ChangeState then associated State Handler called

    Adding command

    Create in your Telegram Module public medthod with StateHandlerAttribute
    Telegram Module must be in Group

    using TelegramModularFramework.Modules;
    
    public class SampleModule: TelegramModule
    {
        [Command]
        [Action]
        [Summary("Sets name")]
        public async Task EnterName()
        {
            await ReplyAsync($"Enter name:");
            await ChangeState("sample");
        }
    
        [Group("sample")]
        public class SampleState: TelegramModule
        {
            [StateHandler]
            public async Task HandleState(string input)
            {
                if (input == null) throw new ValidationError("No text in message", nameof(input), 0);
                await ReplyAsync($"You entered: {input}");
                await ChangeState("/"); // Return back
            }
        }
    }
    

    State path generates from module group

    Arguments

    If ParseArgs is false State Handler retrieve on string argument equals to message text

    If ParseArgs is true arguments parsed as commands do

    [StateHandler(parseArgs:true)]
    

    Run Mode

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

    Summary

    To add summary to command use SummaryAttribute

    [Summary("Do things")]
    

    On State Executed

    Subscribe to StateExecuted event to handle state post execution

    Exceptions

    If state executed unsuccessfully handle Exception
    Possible exception:

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