updateBot method

Future<void> updateBot({
  1. required Bot bot,
})

Update a bot in this botnoi chatbot server.

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

Implementation

Future<void> updateBot({
  required Bot bot,
}) async {
  try {
    if (bot.id == null) {
      GetIt.I<BotnoiClient>().finishedFailed();
      GetIt.I<BotnoiClient>().error.add("[updateBot] : bot ${bot.botName} doesn't have an id, try reloading it");
      return;
    }
    Uri url = Uri.parse("${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/bot");
    http.Response response = await http.put(
      url,
      headers: _getHeader,
      body: jsonEncode(bot.toJson()),
    );
    if (response.statusCode == 200 || response.statusCode == 204) {
      GetIt.I<BotnoiClient>().finishedSuccessfully();
      return;
    }
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add("[updateBot] : ${response.reasonPhrase ?? "ERROR"}");
  } catch (e) {
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add("[updateBot] : $e");
  }
}