teledart_app 1.0.1-dev.0 copy "teledart_app: ^1.0.1-dev.0" to clipboard
teledart_app: ^1.0.1-dev.0 copied to clipboard


API written on top of teledart, aimed to simplify work with commands and callbacks

teledart_app #

API written on top of teledart, aimed to simplify work with commands and callbacks


Purpose #

This API should be useful to build interactive bots to perform different actions depending on user input either command, plain text or button push

Basic usage #

  1. Inherit new command inherited from Command class:
class ExampleCommand extends Command {
  ArgParser? getParser() => null;

  String get name => 'example';

  void run(Message message, TelegramEx telegram) {
    telegram.sendMessage(, 'Hello, World!');
  1. Create application class, inherited from TeledartApp class:

class ExampleApp extends TeledartApp {
  ExampleApp(String token) : super(token);

  List<CommandConstructor> get commands => [];

  List<MiddlewareConstructor> get middleware => [];

  void onError(Object exception, Update data, TelegramEx telegram) {
    print('Hello, Error!');
  1. List your command in commands getter of application class:
  List<CommandConstructor> get commands => [() => ExampleCommand()];
  1. Run application in main function. Don't forget to pass valid bot key into constructor.
void main() {
  final app = ExampleApp('bot key here');;
  1. Type command "/example" into chat with bot. And see "Hello, World!" as an answer.

See full working example at simple_command.dart

Handling multiple actions in one command #

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.

Create your's application class as in basic example. But create new command, extending ComplexCommand class instead of Command:

class ExampleComplexCommand extends ComplexCommand {
  String get name => 'complex';

  Map<String, CmdAction> get actionMap => {
        'first': onFirstButton,
        'second': onSecondButton

  void onNoAction(Message message, TelegramEx telegram) {
    telegram.sendMessage(, 'onNoAction function',
        reply_markup: InlineKeyboardMarkup(inline_keyboard: [
                text: 'onFirstButton call', callback_data: buildAction('first'))
                text: 'onSecondButton call', callback_data: buildAction('second'))

  void onFirstButton(Message message, TelegramEx telegram) {
    telegram.sendMessage(, 'onFirstButton pressed!');

  void onSecondButton(Message message, TelegramEx telegram) {
    telegram.sendMessage(, 'onSecondButton pressed!');

At actionMap we defined two actions: "first" and "second", and each refers to function wich will handle corresponding action. At noAction function we specified, what to do if no action passed, for example if only "/complex" command had been typed or passed through callback_query, withought additional parameters.

Using buildAction we created string representation of our command with action specified.

If different actions are not enouth, we could use additional parameters. First, we need to describe parameters using getParser getter of command class:

  ArgParser getParser() => super.getParser()..addOption('param1')..addOption('param2');

Then, we could create additional button, witch calls new action:

    text: 'onButtonWithParameters call',
    callback_data: buildAction('with-parameters', {
        'param1': 'value1', 
        'param2': 'value2'

Define new action in actionMap:

'with-parameters': onButtonWithParameters,

And implement new action function:

void onButtonWithParameters(Message message, TelegramEx telegram) {
    final txtParameters = 'param1: ' +
        arguments?['param1'] +
        '\r\n' +
        'param2: ' +
        arguments?['param2'] +
        'onButtonWithParameters pressed!\r\n'
                'parameters are:\r\n' +

We can access custom parameters, using arguments variable.

See full example at complex_command.dart

Middleware #

In case you need access raw Update object before any command will happen, use separate middleware class.

See working example at middleware.dart

pub points



API written on top of teledart, aimed to simplify work with commands and callbacks

Repository (GitHub)
View/report issues


unknown (LICENSE)


args, meta, teledart


Packages that depend on teledart_app