invokeSync method

Map invokeSync(
  1. String method, {
  2. Map<String, dynamic>? parameters,
  3. required int clientId,
  4. bool isThrowOnError = true,
})

call api latest Tdlib-Methods example:

tg.invokeSync(
 "parseTextEntities",
 parameters: {
   "parse_mode": {
     "@type": "textParseModeHTML",
    },
   "text": text
  },
  clientId: tg.client_id,
);

Implementation

Map invokeSync(
  String method, {
  Map<String, dynamic>? parameters,
  required int clientId,
  bool isThrowOnError = true,
}) {
  parameters ??= {};
  if (clientId == 0) {
    clientId = client_id;
  }

  String random = generateUuid(15);
  if (parameters is Map) {
    parameters["@extra"] = random;
  } else {
    parameters["@extra"] = random;
  }

  var requestMethod = {
    "@type": method,
    "client_id": clientId,
    ...parameters,
  };

  Map result = client_execute(clientId, requestMethod);
  if (result["@type"] == "error") {
    if (!isThrowOnError) {
      return result;
    }
    result["invoke_request"] = requestMethod;
    throw result;
  }
  return result;
}