updateObject method
Update an object of this bot.
{object} is the updated version of the object that you want to update (object's id must not be changed).
Implementation
Future<void> updateObject({
required BotObject object,
}) async {
try {
if (object.id == null) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("this object has no id");
return;
}
object.belongTo(_bot);
Uri url = Uri.parse("${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/intent");
http.Response response = await http.put(
url,
headers: _getHeader,
body: jsonEncode(object.toJson()),
);
if (response.statusCode == 200 || response.statusCode == 204) {
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());
}
}