findBots method

Future<List<Bot>?> findBots()

Find all bots in this botnoi chatbot server.

Implementation

Future<List<Bot>?> findBots() async {
  try {
    Uri url = Uri.parse("${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/bot");
    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["data"] as List).map((e) => Bot.fromJson(e as Map)).toList();
    }
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add("[findBots] : ${response.reasonPhrase ?? "ERROR"}");
    return null;
  } catch (e) {
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add("[findBots] : $e");
    return null;
  }
}