Command class abstract
Base class for telegram command handler
Use to implement handler for some telegram command like "/start" and so on. Each command in application is treated as linux cli command. It means that each command can have number of options. For example, "/start" could be called with additional arguments like "/start --arg1=value1 --arg2=value2" and so on.
This mechanics will work either when user send command into chat explicitly as text message and when command is extracted from callback_query, when user push any inline button
To make command to handle InlineKeyboardButton
action, pass command string in format
"/start --arg1=value1 --arg2=value2" to the callback_data
parameter
of InlineKeyboardButton
constructor.
See https://core.telegram.org/bots/api#inlinekeyboardbutton
Keep in mind that callback_data
is limited to 1-64 bytes, so don't make your's
commands string representations too long!
To declare list of arguments which can be processed, implement getParser. See https://pub.dev/packages/args for details
To get string representation of command use buildCommandCall method. It also allows to pass arguments you need.
To create new command instance with arguments, use Command.withArguments constructor. Usually you needn't that, application will create all commands for you automatically
run function should implement business logic of application: process user input, send next messages, create inline buttons and so on.
Each command instance is created before processing user's request. New command call will create new instance. If you want to keep one instance between command calls, use []
Functions scheduleMessageDelete and deleteScheduledMessages should be useful to control message flow.
- Mixed in types
- Implementers
Constructors
- Command()
-
Command.withArguments(CommandConstructor cmdBuilder, Map<
String, String> args, AsyncErrorHandlerFunction? asyncErrorHandler) -
Build command with arguments
factory
- Command.withArgumentsFrom(CommandConstructor cmdBuilder, Command other)
-
"Copy constructor" allows to clone arguments from existing command to new one
factory
Properties
- arguments ↔ ArgResults?
-
Additional options for command
getter/setter pair
- asyncErrorHandler ↔ AsyncErrorHandlerFunction?
-
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- lockDuration → Duration
-
no setter
- 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 setter
- name → String
-
The name of command
no setter
- 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 setter
Methods
-
buildCommandCall(
[Map< String, String> parameters = const {}]) → String - Builds string representation of command call
-
callMeOnNextMessage(
int chatId) → void - Preserve command instance till next message in specified chat.
-
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
-
lock(
) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reset(
) → void - Reset all arguments
-
run(
Message message, TelegramEx telegram) → dynamic - Main function for your business logic
-
runWithErrorHandler(
Message message, TelegramEx telegram, {dynamic additionalData}) → dynamic -
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.
override
-
unlock(
) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited