findIntents method

Future<List<BotIntent>?> findIntents()

Find all intents of this bot.

Implementation

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