public static class NlpListener.DefaultImpls
Used to customize behaviour of NLP parsing - and also to monitor NLP requests - on bot side.
Has to be registered using ai.tock.bot.engine.BotRepository.registerNlpListener.
@Nullable public static Intent handleKeyword(NlpListener $this, @NotNull java.lang.String sentence)
Used to handle "secret" keywords.
@Nullable public static IntentAware findIntent(NlpListener $this, @NotNull UserTimeline userTimeline, @NotNull Dialog dialog, @NotNull Event event, @NotNull ai.tock.nlp.api.client.model.NlpResult nlpResult)
This method is automatically called by the bot after a NLP request in order to select an intent. Overrides it if you need more control on intent choice.
If it returns null, ai.tock.bot.definition.BotDefinition.findIntent is called.
Default returns null.
@NotNull public static java.util.List<ai.tock.bot.engine.dialog.EntityValue> evaluateEntities(NlpListener $this, @NotNull UserTimeline userTimeline, @NotNull Dialog dialog, @NotNull Event event, @NotNull ai.tock.nlp.api.client.model.NlpResult nlpResult)
Allows custom entity evaluation - default returns empty list.
@NotNull public static java.util.List<ai.tock.bot.engine.nlp.NlpEntityMergeContext> sortEntitiesToMerge(NlpListener $this, @NotNull java.util.List<ai.tock.bot.engine.nlp.NlpEntityMergeContext> entities)
Defines custom sort new entity values. This is useful when you want to evaluate an entity role only after an other entity role has been evaluated (entity dependence use case). Default does nothing.
@NotNull public static NlpEntityMergeContext mergeEntityValues(NlpListener $this, @NotNull DialogState dialogState, @NotNull Action action, @NotNull NlpEntityMergeContext entityToMerge)
Allows to override class NlpEntityMergeContext before trying to merge the entity context.
class NlpEntityMergeContextpublic static void success(NlpListener $this, @NotNull ai.tock.nlp.api.client.model.NlpQuery query, @NotNull ai.tock.nlp.api.client.model.NlpResult result)
Called when nlp request is successful.
public static void error(NlpListener $this, @NotNull ai.tock.nlp.api.client.model.NlpQuery query, @NotNull Dialog dialog, @Nullable java.lang.Throwable throwable)
Called when nlp request is throwing an error.
Using this method, you can for example redirect to a custom story which will handle the error.
object MyNlpListener : NlpListener {
override fun error(query: NlpQuery, dialog: Dialog, throwable: Throwable?) {
super.error(query, dialog, throwable)
dialog.state.currentIntent = bot.myCustomErrorStory.mainIntent()
}
}