public NlpListener
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 Intent handleKeyword(@NotNull java.lang.String sentence)
Used to handle "secret" keywords.
@Nullable IntentAware findIntent(@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
java.util.List<ai.tock.bot.engine.dialog.EntityValue> evaluateEntities(@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
java.util.List<ai.tock.bot.engine.nlp.NlpEntityMergeContext> sortEntitiesToMerge(@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 NlpEntityMergeContext mergeEntityValues(@NotNull DialogState dialogState, @NotNull Action action, @NotNull NlpEntityMergeContext entityToMerge)
Allows to override class NlpEntityMergeContext before trying to merge the entity context.
class NlpEntityMergeContextvoid success(@NotNull
ai.tock.nlp.api.client.model.NlpQuery query,
@NotNull
ai.tock.nlp.api.client.model.NlpResult result)
Called when nlp request is successful.
void error(@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()
}
}