createObject method

Future<void> createObject({
  1. required BotObject object,
})

Create a new object for this bot.

In Botnoi Chatbot, objects are anything that you want your bot to use that isn't text (eg. images, audio, flex message, buttons, api, etc.).

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

Implementation

Future<void> createObject({
  required BotObject object,
}) async {
  try {
    object.belongTo(_bot);
    Uri url =
        Uri.parse("${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/object/${object.objectType}");
    http.Response response = await http.post(
      url,
      headers: _getHeader,
      body: jsonEncode(object.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());
  }
}