Tdlib constructor
Tdlib({
- String? pathTdl,
- TelegramClientLibraryTdlibOptionParameter? clientOption,
- int task_max_count = 10000,
- int task_min_cooldown = 10,
- Duration? invokeTimeOut,
- String event_invoke = "invoke",
- String event_update = "update",
- Duration? delayUpdate,
- double timeOutUpdate = 1.0,
- EventEmitter? eventEmitter,
- Duration? delayInvoke,
- bool isAutoGetChat = false,
- FutureOr<
Map> on_get_invoke_data()?, - FutureOr<
void> on_receive_update(- dynamic update,
- TdlibBase libTdJson
- FutureOr<
String> on_generate_extra_invoke()?, - 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,
});