Search Results for

    Show / Hide Table of Contents

    Commands

    Text messages starting with /

    Adding command

    Create in your Telegram Module public medthod with CommandAttribute

    using TelegramModularFramework.Modules;
    
    public class SampleModule: TelegramModule
    {
        [Command]
        public async Task Start()
        {
            await ReplyAsync($"Welcome!");
        }
    }
    

    By default, command name generates from method name CommandName -> /commandname
    You can specify name by passing name argument to CommandAttribute
    Name cannot contain spaces

    [Command("test")]
    

    Arguments

    String after command name parsed as command arguments
    Adding parameters to a command is done by adding parameters to the command handler method

    [Command]
    public async Task Command(int number, float numberFloat, double numberDouble, bool boolean)
    {
        await ReplyAsync($"{number} {numberFloat} {numberDouble} {boolean}");
    }
    

    If string contains spaces it can be wrapped in quotes /command "String with spaces"
    Available typereaders and guide how to make custom one are present in TypeReaders

    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")]
    

    SetMyCommands

    You can call SetMyCommands() to set list of visible to bot
    Command must have summary To hide set hideFromList argument to CommandAttribute

    [Command(hideFromList: true)]
    

    On Command Executed

    Subscribe to CommandExecuted event to handle command post execution

    Exceptions

    If command 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
    ☀
    ☾