createBot method

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

Create a new bot for this botnoi chatbot server.

{bot} is the bot that you want to create.

Implementation

Future<void> createBot({required Bot bot}) async {
  try {
    Uri url = Uri.parse("${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/bot");
    http.Response response = await http.post(
      url,
      headers: _getHeader,
      body: jsonEncode(bot.toJson()),
    );
    if (response.statusCode == 201) {
      GetIt.I<BotnoiClient>().finishedSuccessfully();
      return;
    }
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add(response.reasonPhrase ?? "ERROR");
  } catch (e) {
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add(e.toString());
  }
}