trainChitchat method

Future<void> trainChitchat({
  1. required String keyword,
  2. required String message,
})

Train a chitchat for this bot. "Chitchat" is non-intent-based conversation that can be trained using a keyword-message pair.

{keyword} is the text recieved from the users.

{message} is the text that the bot will respond to the users.

Implementation

Future<void> trainChitchat({
  required String keyword,
  required String message,
}) async {
  try {
    Uri url = Uri.parse("${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/training/chitchat");
    http.Response response = await http.post(
      url,
      headers: _getHeader,
      body: jsonEncode({
        "bot_id": _bot.id,
        "keyword": keyword,
        "response": message,
      }),
    );
    if (response.statusCode == 200) {
      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());
  }
}