Class StoryHandlerBase
-
- All Implemented Interfaces:
-
ai.tock.bot.definition.IntentAware,ai.tock.bot.definition.StoryHandler,ai.tock.translator.I18nKeyProvider
public abstract class StoryHandlerBase<T extends StoryHandlerDefinition> implements StoryHandler, I18nKeyProvider, IntentAware
Base implementation of StoryHandler. Provides also a convenient implementation of I18nKeyProvider to support i18n.
-
-
Constructor Summary
Constructors Constructor Description StoryHandlerBase(String mainIntentName, String i18nNamespace, Long breath)
-
Method Summary
Modifier and Type Method Description final LonggetBreath()Convenient value to wait before next answer sentence. Function1<BotBus, Object>checkPreconditions()Checks preconditions - if BotBus.end is called, StoryHandlerDefinition.handle is not called and the handling of bot answer is over. abstract TnewHandlerDefinition(BotBus bus, Object data)Instantiates new instance of T. final <T extends StoryHandlerDefinition> StoryStep<?>selectStepFromStoryHandlerAndData(T def, Object data, StoryDefinition storyDefinition)Selects step from HandlerDef, optional data and StoryDefinition. final Unithandle(BotBus bus)Receive a message from the bus. Doublesupport(BotBus bus)What is the probability of bot support for the current request? StoryDefinitionfindStoryDefinition(BotBus bus)Finds the story definition of this handler. final UnithandleAndSwitchStory(BotBus bus)Handles the action and switches the context to the underlying story definition. I18nLabelValuei18n(CharSequence defaultLabel, List<Object> args)final I18nLabelValuei18nKey(String key, CharSequence defaultLabel, Object args)Gets an i18n label with the specified key. final I18nLabelValuei18nKey(String key, CharSequence defaultLabel, Set<I18nLocalizedLabel> defaultI18n, Object args)Gets an i18n label with the specified key and defaults. IntentwrappedIntent()-
-
Method Detail
-
checkPreconditions
Function1<BotBus, Object> checkPreconditions()
Checks preconditions - if BotBus.end is called, StoryHandlerDefinition.handle is not called and the handling of bot answer is over.
-
newHandlerDefinition
abstract T newHandlerDefinition(BotBus bus, Object data)
Instantiates new instance of T.
-
selectStepFromStoryHandlerAndData
final <T extends StoryHandlerDefinition> StoryStep<?> selectStepFromStoryHandlerAndData(T def, Object data, StoryDefinition storyDefinition)
Selects step from HandlerDef, optional data and StoryDefinition.
-
handle
final Unit handle(BotBus bus)
Receive a message from the bus.
- Parameters:
bus- the bus used to get the message and send the answer
-
support
Double support(BotBus bus)
What is the probability of bot support for the current request?
- Returns:
a probability between 0.0 (not supported) and 1.0 (supported!)
-
findStoryDefinition
StoryDefinition findStoryDefinition(BotBus bus)
Finds the story definition of this handler.
-
handleAndSwitchStory
final Unit handleAndSwitchStory(BotBus bus)
Handles the action and switches the context to the underlying story definition.
-
i18n
I18nLabelValue i18n(CharSequence defaultLabel, List<Object> args)
-
i18nKey
final I18nLabelValue i18nKey(String key, CharSequence defaultLabel, Object args)
Gets an i18n label with the specified key. Current namespace is used for the categorization.
-
i18nKey
final I18nLabelValue i18nKey(String key, CharSequence defaultLabel, Set<I18nLocalizedLabel> defaultI18n, Object args)
Gets an i18n label with the specified key and defaults. Current namespace is used for the categorization.
-
wrappedIntent
Intent wrappedIntent()
-
-
-
-