createObject method
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.belongToBot(_bot);
Uri url = Uri.parse(
"${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/object/${object.objectType.stringType}");
http.Response response = await http.post(
url,
headers: _getHeader,
body: jsonEncode(object.toJson()),
);
if (response.statusCode == 201 || response.statusCode == 200) {
GetIt.I<BotnoiClient>().finishedSuccessfully();
return;
}
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>()
.error
.add("[createObject] : ${response.reasonPhrase ?? "ERROR"}");
} catch (e) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[createObject] : $e");
}
}