Tdlib constructor

Tdlib({
  1. String? pathTdl,
  2. TelegramClientLibraryTdlibOptionParameter? clientOption,
  3. int task_max_count = 10000,
  4. int task_min_cooldown = 10,
  5. Duration? invokeTimeOut,
  6. String event_invoke = "invoke",
  7. String event_update = "update",
  8. Duration? delayUpdate,
  9. double timeOutUpdate = 1.0,
  10. EventEmitter? eventEmitter,
  11. Duration? delayInvoke,
  12. bool isAutoGetChat = false,
  13. FutureOr<Map> on_get_invoke_data(
    1. String extra,
    2. int client_id,
    3. TdlibBase libTdJson
    )?,
  14. FutureOr<void> on_receive_update(
    1. dynamic update,
    2. TdlibBase libTdJson
    )?,
  15. FutureOr<String> on_generate_extra_invoke(
    1. int client_id,
    2. TdlibBase libTdJson
    )?,
  16. bool isInvokeThrowOnError = true,
})

Cheatset

Minimalist Setup

Tdlib tg = Tdlib(
  // https://github.com/tdlib/td
  pathTdl: "libtdjson.so",
  clientOption: {
    // https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1set_tdlib_parameters.html
    "api_id": 0,
    "api_hash": "a",
    'database_directory': Directory.current.path,
    'files_directory': Directory.current.path,
    "new_verbosity_level": 0,
    "database_key": "",
  },
);

Advanced Setup

telegram database

int api_id = 0; // telegram api id
String api_hash = ""; // telegram api hash
int owner_chat_id = 0; // owner telegram chat id
Map<String, Map> extraData = {};
Tdlib tg = Tdlib(
  pathTdl: "libtdjson.${getFormatLibrary}",
  clientOption: {
    'api_id': api_id,
    'api_hash': api_hash,
  },
  invokeTimeOut: Duration(minutes: 10),
  delayInvoke: Duration(milliseconds: 10),
  on_get_invoke_data: (extra, client_id) async {
    print("Get Data");
    while (true) {
      await Future.delayed(Duration(milliseconds: 1));
      Map? data = extraData[extra];
      if (data != null) {
        data = data.clone();
        print("send: ${data}");
        extraData.remove(extra);
        return data;
      }
    }
  },
  on_receive_update: (update, libTdJson) async {
    if (update is TdlibIsolateReceiveData) {
      try {
        if (tdlibIsolateReceiveData.updateData["@extra"] is String) {
          extraData[tdlibIsolateReceiveData.updateData["@extra"]] = tdlibIsolateReceiveData.updateData;
        } else {
          libTdJson.event_emitter.emit(libTdJson.event_update, null, tdlibIsolateReceiveData);
        }
      } catch (e) {
        libTdJson.event_emitter.emit(libTdJson.event_update, null, tdlibIsolateReceiveData);
      }
    } else if (update is TdlibIsolateReceiveDataError) {
      TdlibIsolateReceiveDataError tdlibIsolateReceiveDataError = update;
      try {
        TdlibClient? tdlibClient = libTdJson.clients.getClientById(tdlibIsolateReceiveDataError.clientId);
        if (tdlibClient != null) {
          tdlibClient.close();
        }
      } catch (e) {}
    }
  },
);

More configuration Tdlib-Parameters

Implementation

//       TdlibIsolateReceiveData tdlibIsolateReceiveData = update;
///       try {
///         if (tdlibIsolateReceiveData.updateData["@extra"] is String) {
///           extraData[tdlibIsolateReceiveData.updateData["@extra"]] = tdlibIsolateReceiveData.updateData;
///         } else {
///           libTdJson.event_emitter.emit(libTdJson.event_update, null, tdlibIsolateReceiveData);
///         }
///       } catch (e) {
///         libTdJson.event_emitter.emit(libTdJson.event_update, null, tdlibIsolateReceiveData);
///       }
///     } else if (update is TdlibIsolateReceiveDataError) {
///       TdlibIsolateReceiveDataError tdlibIsolateReceiveDataError = update;
///       try {
///         TdlibClient? tdlibClient = libTdJson.clients.getClientById(tdlibIsolateReceiveDataError.clientId);
///         if (tdlibClient != null) {
///           tdlibClient.close();
///         }
///       } catch (e) {}
///     }
///   },
/// );
/// ```
///
/// More configuration [Tdlib-Parameters](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1tdlib_parameters.html)
Tdlib({
  super.pathTdl,
  super.clientOption,
  super.task_max_count,
  super.task_min_cooldown,
  super.invokeTimeOut,
  super.event_invoke = "invoke",
  super.event_update = "update",
  super.delayUpdate,
  super.timeOutUpdate,
  super.eventEmitter,
  super.delayInvoke,
  super.isAutoGetChat = false,
  super.on_get_invoke_data,
  super.on_receive_update,
  super.on_generate_extra_invoke,
  super.isInvokeThrowOnError,
});