ComplexCommand class abstract

Special command type, allows to separate business logic into different functions

Suppose, you have sent a message to user and put three InlineKeyboardButton to make choice. How would you handle user's click to every button?

  1. You can create separate command for each button.
  2. You can create one command and call it with different options depending on what button has been clicked The first solution fill generate a lot of boilerplate code. The second is more preferable. This class just simplify creating commands with option, indicating different actions.

In new class specify a number of functions, representing different actions. The type of functions must be CmdAction.

In actionMap specify list of action names and corresponding CmdAction functions for each action.

Use buildAction to create command's string representation and pass it into InlineKeyboardButton call, to the callback_data property.

As result, when user press a button, command instance will be created and CmdAction function, corresponding to button's action, will be called. If no valid function wil be found or action parameter will be omitted - onNoAction function will be called.

There is no more need to reimplement run function, but you still can do it in some specific cases. You also no more need to reimplement getParser, unless you want to add additional parameters to your's action.

Use action to determine current action, if you are not into CmdAction function.

Try to keep action names as short as possible due to Telegram limitation on callback_data length: 1-64 bytes. See https://core.telegram.org/bots/api#inlinekeyboardbutton

Inheritance

Constructors

ComplexCommand()
ComplexCommand.withAction(CommandConstructor cmdBuilder, String act, AsyncErrorHandlerFunction? asyncErrorHandler, [Map<String, String>? args])
factory

Properties

action String
no setter
actionMap Map<String, CmdAction>
no setter
arguments ↔ ArgResults?
Additional options for command
getter/setter pairinherited
asyncErrorHandler AsyncErrorHandlerFunction?
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
lockDuration Duration
no setterinherited
lockOnRun bool
Desktop and web Telegram client both has issue: fast double-click on an button produces multiple equivalent events to occur, before the button will be hidden by code or blocked by client.
no setterinherited
message ↔ Message
latefinal
name String
The name of command
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
system bool
Should be command called by user directly, or it is only for internal use?
no setterinherited
telegram TelegramEx
latefinal

Methods

buildAction(String actionName, [Map<String, String>? parameters]) String
buildCommandCall([Map<String, String> parameters = const {}]) String
Builds string representation of command call
inherited
callMeOnNextMessage(int chatId) → void
Preserve command instance till next message in specified chat.
inherited
catchAsyncError(dynamic functionResult, {dynamic additionalData}) Future
inherited
deleteScheduledMessages(TelegramEx telegram, {int? chatId, List<String>? tags}) int
Delete messages, previously marked by scheduleMessageDelete
inherited
getParser() → ArgParser
Configured parser instance to parse arguments from string
override
lock() → void
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onNoAction(Message message, TelegramEx telegram) → void
Like 404 page in web
reset() → void
Reset all arguments
inherited
run(Message message, TelegramEx telegram) → void
Main function for your business logic
override
runWithErrorHandler(Message message, TelegramEx telegram, {dynamic additionalData}) → dynamic
inherited
scheduleMessageDelete(int chatId, int messageId, {String? tag}) → void
Mark message to be deleted with next call of deleteScheduledMessages
inherited
toString() String
A string representation of this object.
inherited
unlock() → void
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

ACTION → const String