updateIntent method

Future<void> updateIntent({
  1. required BotIntent intent,
})

Update an intent of this bot.

  • {intent} is the updated version of the intent that you want to update (intent's id must not be changed).

Implementation

Future<void> updateIntent({
  required BotIntent intent,
}) async {
  try {
    if (intent.id == null) {
      GetIt.I<BotnoiClient>().finishedFailed();
      GetIt.I<BotnoiClient>()
          .error
          .add("[updateIntent] : this intent has no id");
      return;
    }
    intent.belongToBot(_bot);
    Uri url = Uri.parse(
        "${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/intent");
    http.Response response = await http.put(
      url,
      headers: _getHeader,
      body: jsonEncode(intent.toJson()),
    );
    if (response.statusCode == 200 || response.statusCode == 204) {
      GetIt.I<BotnoiClient>().finishedSuccessfully();
      return;
    }
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>()
        .error
        .add("[updateIntent] : ${response.reasonPhrase ?? "ERROR"}");
  } catch (e) {
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add("[updateIntent] : $e");
  }
}