run method

  1. @mustCallSuper
void run()

Main application flow

Could be overridden to add custom initialisation cycle.

Implementation

@mustCallSuper
void run() async {
  final polling = LongPolling(telegram);
  var stream = polling.onUpdate();

  final router = _Router(telegram);
  router.asyncErrorHandler = onError;
  for (var cmdBuilder in commands) {
    router.registerCommand(cmdBuilder);
  }
  print('${commands.length} commands registered.');

  for (var cmdBuilder in middleware) {
    router.registerMiddleware(cmdBuilder);
  }
  print('${middleware.length} middleware registered.');

  stream.listen((Update data) {
    try {
      router.dispatch(data);
    } catch (exception, trace) {
      onError(exception, trace, data);
    }
  });
  print('Listening for updates from Telegram...');
  await polling.start();
}