getMe method

Future<Map> getMe({
  1. required int clientId,
  2. bool? isUseCache,
  3. Duration? durationCacheExpire,
  4. String? extra,
})

call api getMe with return human api result:

{
  "ok": true,
  "result": {
    "id": 12345,
    "first_name": "Hello World",
    "last_name": "Hello world",
    "username": "azkadev",
    "status": "recently",
    "type_account": "user",
    "type": "private",
    "is_bot": false,
    "language_code": "id",
    "detail": {

    }
  }
}

Implementation

Future<Map> getMe({
  required int clientId,
  bool? isUseCache,
  Duration? durationCacheExpire,
  String? extra,
}) async {
  //
  var get_me = await invoke(
    "getMe",
    clientId: clientId,
    isUseCache: isUseCache,
    durationCacheExpire: durationCacheExpire,
    extra: extra,
  );
  Map result = {};
  result["id"] = get_me["id"];
  result["is_bot"] = false;
  result["first_name"] = get_me["first_name"];
  if (get_me["last_name"].toString().isNotEmpty) {
    result["last_name"] = get_me["last_name"];
  }
  if (get_me["username"] is String) {
    result["username"] = get_me["username"];
  }

  if (get_me["usernames"] is Map) {
    Map get_user_usernames = (get_me["usernames"] as Map);
    result["usernames"] = get_me["usernames"];
    if (get_user_usernames["active_usernames"] is List) {
      if ((get_user_usernames["active_usernames"] as List).isNotEmpty) {
        result["username"] =
            (get_user_usernames["active_usernames"] as List).first;
      }
    }
  }

  if (get_me["phone_number"].toString().isNotEmpty) {
    result["phone_number"] = get_me["phone_number"];
  }
  result["status"] = get_me["status"]["@type"]
      .toString()
      .toLowerCase()
      .replaceAll(RegExp("userStatus", caseSensitive: false), "");
  result["type_account"] = get_me["type"]["@type"]
      .toString()
      .toLowerCase()
      .replaceAll(RegExp("userType", caseSensitive: false), "");
  result["type"] = "private";
  if (result["type_account"] == "bot") {
    result["is_bot"] = true;
  }
  if (get_me["language_code"].toString().isNotEmpty) {
    result["language_code"] = get_me["language_code"];
  }
  result["detail"] = {};
  get_me.forEach((key, value) {
    if (value is bool) {
      result["detail"][key.toString()] = value;
    }
  });

  get_me["type"].forEach((key, value) {
    if (value is bool) {
      result["detail"][key.toString()] = value;
    }
  });

  try {
    if (get_me["profile_photo"] is Map) {
      result["profile_photo"] = {
        "id": get_me["profile_photo"]["id"],
        "path": "",
        "file_id": "",
      };
      if (get_me["profile_photo"]["big"] is Map) {
        (get_me["profile_photo"]["big"]["local"] as Map)
            .forEach((key, value) {
          if (key != "@type") {
            result["profile_photo"][key.toString()] = value;
          }
        });
        if (get_me["profile_photo"]["big"]["remote"] is Map) {
          result["profile_photo"]["file_id"] =
              get_me["profile_photo"]["big"]["remote"]["id"];
        }
      }
    }
  } catch (e) {
    return {"ok": true, "result": result, "error": e};
  }

  return {"ok": true, "result": result};
}