findObjects method
Find all objects of this bot with a specific type.
{type} is the type of object that you want to find.
Implementation
Future<List<BotObject>?> findObjects({required String type}) async {
try {
Uri url = Uri.parse(
"${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/object/$type?bot_id=${_bot.id}");
http.Response response = await http.get(
url,
headers: _getHeader,
);
if (response.statusCode == 200) {
dynamic result = jsonDecode(utf8.decode(response.bodyBytes));
GetIt.I<BotnoiClient>().finishedSuccessfully();
return (result as List).map((e) => BotObject.fromJson(e as Map)..belongTo(_bot)).toList();
}
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add(response.reasonPhrase ?? "ERROR");
return null;
} catch (e) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add(e.toString());
return null;
}
}