trainChitchat method

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

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

  • {keyword} is the text recieved from the users.

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

Implementation

Future<void> trainChitchat({
  required String keyword,
  required String reaction,
}) 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": reaction,
      }),
    );
    if (response.statusCode == 200) {
      GetIt.I<BotnoiClient>().finishedSuccessfully();
      return;
    }
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>()
        .error
        .add("[trainChitchat] : ${response.reasonPhrase ?? "ERROR"}");
  } catch (e) {
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add("[trainChitchat] : $e");
  }
}