getIntent method

Future<BotIntent?> getIntent(
  1. String name, {
  2. String? botName,
})

Get the collected intent by name.

  • {name} is the name of the intent.

  • {botName} is the name of the bot that the intent belongs to. If not specified, the bot that is currently collected will be used. {botName} should not be specified if the bot is already collected to avoid unnecessary loading.

Implementation

Future<BotIntent?> getIntent(String name, {String? botName}) async {
  if (botName == null && _bot == null) {
    GetIt.I<BotnoiClient>().error.add(
        "[collector.getIntent] : A bot must be collected first or the botName must be specified");
    return null;
  }
  String key = "${botName ?? _bot?.botName}/$name";
  if (_intents.containsKey(key)) {
    return _intents[key];
  } else {
    if (implicitCollecting) {
      if (botName != null && botName != _bot?.botName) {
        Bot? loadedBot =
            await BotnoiChatbot.serverInstance.findBotWithName(botName);
        if (loadedBot != null) {
          BotIntent? loadedIntent =
              await loadedBot.opt.findIntentWithName(name);
          if (loadedIntent != null) {
            collectIntent(loadedIntent);
            return loadedIntent;
          } else {
            return null;
          }
        } else {
          return null;
        }
      }
      if (_bot != null) {
        BotIntent? loadedIntent = await _bot!.opt.findIntentWithName(name);
        if (loadedIntent != null) {
          collectIntent(loadedIntent);
          return loadedIntent;
        } else {
          return null;
        }
      }
    }
    return null;
  }
}