public static class StoryHandlerDefinition.DefaultImpls
Story handler definitions are used in interface StoryHandler to provide custom context and to manage specific connector behaviour.
Implementations should usually use class StoryHandlerDefinitionBase.
@Nullable public static ConnectorStoryHandler<?> getConnector(StoryHandlerDefinition $this)
The interface ConnectorStoryHandler provided for the current BotBus.targetConnectorType - null if it does not exist.
interface ConnectorStoryHandlerpublic static void answerWith(StoryHandlerDefinition $this, @Nullable java.lang.CharSequence p, @NotNull kotlin.jvm.functions.Function0<? extends java.lang.Object> messageProvider)
Answers with the specified parameters.
$this - used if messageProvider returns nullp - provides the answer - a message or a list of messagesmessageProvider - provides the answer - a message or a list of messages@Nullable public static StoryStep<? extends ai.tock.bot.definition.StoryHandlerDefinition> getStep(StoryHandlerDefinition $this)
public static void setStep(StoryHandlerDefinition $this, @Nullable StoryStep<? extends ai.tock.bot.definition.StoryHandlerDefinition> step)
@Nullable public static java.lang.String getStepName(StoryHandlerDefinition $this)
The name of the step if any.
@Nullable public static java.lang.String getUserText(StoryHandlerDefinition $this)
The text sent by the user if any.
public static boolean isIntent(StoryHandlerDefinition $this, @NotNull IntentAware intentOwner)
To know if the current intent is owned by the interface IntentAware.
interface IntentAware@Nullable public static NlpCallStats nlpStats(StoryHandlerDefinition $this)
Returns the NLP call stats if an NLP call has occurred, null either.
public static boolean isChoiceAction(StoryHandlerDefinition $this)
Is this current action is a class SendChoice?
class SendChoice@Nullable public static java.lang.String choice(StoryHandlerDefinition $this, @NotNull ParameterKey key)
Returns the value of the specified choice parameter, null if the user action is not a class SendChoice
or if this parameter is not set.
class SendChoicepublic static boolean booleanChoice(StoryHandlerDefinition $this, @NotNull ParameterKey key)
Returns true if the specified choice parameter has the "true" value, false either.
public static boolean hasChoiceValue(StoryHandlerDefinition $this, @NotNull ParameterKey param, @NotNull ParameterKey value)
Checks that the specified choice parameter has the specified value.
public static boolean hasActionEntity(StoryHandlerDefinition $this, @NotNull java.lang.String role)
Returns true if the current action has the specified entity role.
public static boolean hasActionEntity(StoryHandlerDefinition $this, @NotNull ai.tock.nlp.api.client.model.Entity entity)
Returns true if the current action has the specified entity role.
@Nullable public static <T extends Value> T entityValue(StoryHandlerDefinition $this, @NotNull java.lang.String role, @NotNull kotlin.jvm.functions.Function1<? super ai.tock.bot.engine.dialog.EntityValue,? extends T> valueTransformer)
Returns the current value for the specified entity role.
@Nullable public static <T extends Value> T entityValue(StoryHandlerDefinition $this, @NotNull ai.tock.nlp.api.client.model.Entity entity, @NotNull kotlin.jvm.functions.Function1<? super ai.tock.bot.engine.dialog.EntityValue,? extends T> valueTransformer)
Returns the current value for the specified entity.
@Nullable public static java.lang.String entityText(StoryHandlerDefinition $this, @NotNull ai.tock.nlp.api.client.model.Entity entity)
Returns the current text content for the specified entity.
@Nullable public static java.lang.String entityText(StoryHandlerDefinition $this, @NotNull java.lang.String role)
Returns the current text content for the specified entity.
@Nullable public static EntityValue entityValueDetails(StoryHandlerDefinition $this, @NotNull ai.tock.nlp.api.client.model.Entity entity)
Returns the current class EntityValue for the specified entity.
class EntityValue@Nullable public static EntityValue entityValueDetails(StoryHandlerDefinition $this, @NotNull java.lang.String role)
Returns the current class EntityValue for the specified role.
class EntityValuepublic static void changeEntityValue(StoryHandlerDefinition $this, @NotNull java.lang.String role, @Nullable EntityValue newValue)
Updates the current entity value in the dialog.
$this - entity rolerole - the new entity valuenewValue - the new entity valuepublic static void changeEntityValue(StoryHandlerDefinition $this, @NotNull ai.tock.nlp.api.client.model.Entity entity, @Nullable ai.tock.nlp.entity.Value newValue)
Updates the current entity value in the dialog.
$this - the entity definitionentity - the new entity valuenewValue - the new entity valuepublic static void changeEntityValue(StoryHandlerDefinition $this, @NotNull ai.tock.nlp.api.client.model.Entity entity, @NotNull EntityValue newValue)
Updates the current entity value in the dialog.
$this - the entity definitionentity - the new entity valuenewValue - the new entity valuepublic static void changeEntityText(StoryHandlerDefinition $this, @NotNull ai.tock.nlp.api.client.model.Entity entity, @Nullable java.lang.String textContent)
Updates the current entity text value in the dialog.
$this - the entity definitionentity - the new entity text contenttextContent - the new entity text contentpublic static void removeEntityValue(StoryHandlerDefinition $this, @NotNull java.lang.String role)
Removes entity value for the specified role.
public static void removeEntityValue(StoryHandlerDefinition $this, @NotNull ai.tock.nlp.api.client.model.Entity entity)
Removes entity value for the specified role.
public static void removeAllEntityValues(StoryHandlerDefinition $this)
Removes all current entity values.
public static void resetDialogState(StoryHandlerDefinition $this)
Resets all entity values, context values, ai.tock.bot.engine.dialog.DialogState.userLocation and ai.tock.bot.engine.dialog.DialogState.nextActionState but keep entity values history.
@Nullable public static <T> T contextValue(StoryHandlerDefinition $this, @NotNull java.lang.String name)
Returns the persistent current context value.
@Nullable public static <T> T contextValue(StoryHandlerDefinition $this, @NotNull ParameterKey key)
Returns the persistent current context value.
public static void changeContextValue(StoryHandlerDefinition $this, @NotNull java.lang.String name, @Nullable java.lang.Object value)
Updates persistent context value. Do not store Collection or Map in the context, only plain objects or typed arrays.
public static void changeContextValue(StoryHandlerDefinition $this, @NotNull ParameterKey key, @Nullable java.lang.Object value)
Updates persistent context value.
@Nullable public static <T> T getBusContextValue(StoryHandlerDefinition $this, @NotNull ParameterKey key)
Returns the non persistent current context value. Bus context values are useful to store a temporary (ie request scoped) state.
public static void setBusContextValue(StoryHandlerDefinition $this, @NotNull ParameterKey key, @Nullable java.lang.Object value)
Updates the non persistent current context value. Bus context values are useful to store a temporary (ie request scoped) state.
@NotNull public static BotBus endRawText(StoryHandlerDefinition $this, @Nullable java.lang.CharSequence plainText, long delay)
Sends text that should not be translated as last bot answer.
@NotNull public static BotBus end(StoryHandlerDefinition $this, @NotNull Message message, long delay)
Sends interface Message as last bot answer.
interface Message@NotNull public static BotBus end(StoryHandlerDefinition $this, @NotNull MessagesList messages, long initialDelay)
Sends a class MessagesList and end the dialog.
class MessagesList@NotNull public static BotBus end(StoryHandlerDefinition $this, long delay, @NotNull kotlin.jvm.functions.Function1<? super ai.tock.bot.engine.BotBus,? extends java.lang.Object> messageProvider)
Sends messages provided by messageProvider as last bot answer.
if messageProvider returns a CharSequence send it as text. Else call simply end().
messageProvider,
messageProvider,
CharSequence@NotNull public static BotBus end(StoryHandlerDefinition $this, @NotNull java.lang.CharSequence i18nText, long delay, @NotNull java.lang.Object... i18nArgs)
Sends i18nText as last bot answer.
@NotNull public static BotBus end(StoryHandlerDefinition $this, @NotNull java.lang.CharSequence i18nText, @NotNull java.lang.Object... i18nArgs)
Sends i18nText as last bot answer.
@NotNull public static BotBus end(StoryHandlerDefinition $this, long delay)
Send previously registered interface ConnectorMessage as last bot answer.
interface ConnectorMessage@NotNull public static BotBus send(StoryHandlerDefinition $this, @NotNull Message message, long delay)
Sends a interface Message.
interface Message@NotNull public static BotBus send(StoryHandlerDefinition $this, @NotNull MessagesList messages, long initialDelay)
Sends a class MessagesList.
class MessagesList@NotNull public static BotBus send(StoryHandlerDefinition $this, long delay, @NotNull kotlin.jvm.functions.Function1<? super ai.tock.bot.engine.BotBus,? extends java.lang.Object> messageProvider)
Sends messages provided by messageProvider.
if messageProvider returns a CharSequence send it as text. Else call simply send().
messageProvider,
messageProvider,
CharSequence@NotNull public static BotBus send(StoryHandlerDefinition $this, long delay)
Sends previously registered interface ConnectorMessage.
interface ConnectorMessage@NotNull public static BotBus send(StoryHandlerDefinition $this, @NotNull java.lang.CharSequence i18nText, long delay, @NotNull java.lang.Object... i18nArgs)
Sends i18nText.
@NotNull public static BotBus send(StoryHandlerDefinition $this, @NotNull java.lang.CharSequence i18nText, @NotNull java.lang.Object... i18nArgs)
Sends i18nText.
public static void switchStory(StoryHandlerDefinition $this, @NotNull StoryDefinition storyDefinition, @NotNull Intent starterIntent)
Switches the context to the specified story definition (start a new class Story).
class Storypublic static void handleAndSwitchStory(StoryHandlerDefinition $this, @NotNull StoryDefinition storyDefinition, @NotNull Intent starterIntent)
Handles the action and switches the context to the specified story definition.
public static void skipAnswer(StoryHandlerDefinition $this)
Does not send an answer. Synchronous interface Connectors (like Google Assistant or Alexa)
usually do not support skipping answer.
interface Connectorpublic static boolean isFeatureEnabled(StoryHandlerDefinition $this, @NotNull FeatureType feature, boolean p)
Is the feature enabled?
$this - the feature to checkfeature - the default value if the feature state is unknown@NotNull public static ai.tock.translator.I18nLabelValue i18n(StoryHandlerDefinition $this, @NotNull java.lang.CharSequence defaultLabel, @NotNull java.util.List<? extends java.lang.Object> args)
@NotNull public static ai.tock.translator.I18nLabelValue i18n(StoryHandlerDefinition $this, @NotNull java.lang.CharSequence defaultLabel, @NotNull java.lang.Object... args)
@NotNull public static ai.tock.translator.I18nLabelValue i18nKey(StoryHandlerDefinition $this, @NotNull java.lang.String key, @NotNull java.lang.CharSequence defaultLabel, @NotNull java.lang.Object... args)
Gets an i18n label with the specified key.
@Nullable public static java.lang.String getContextId(StoryHandlerDefinition $this)
The current context identifier.
public static long defaultDelay(StoryHandlerDefinition $this, int answerIndex)
Get the default delay between two answers.
public static boolean getTest(StoryHandlerDefinition $this)
Is it a test mode ?
@NotNull public static BotBus withMessage(StoryHandlerDefinition $this, @NotNull ConnectorMessage message)
Adds the specified interface ConnectorMessage to the bus context if the targetConnectorType is compatible.
interface ConnectorMessage,
targetConnectorType@NotNull public static ai.tock.translator.TranslatedSequence translate(StoryHandlerDefinition $this, @Nullable java.lang.CharSequence text, @NotNull java.lang.Object... args)
Translates and format if needed the text with the optionals args.
@NotNull public static ai.tock.translator.TranslatedSequence translate(StoryHandlerDefinition $this, @Nullable ai.tock.translator.I18nLabelValue key)
Translates the specified key.
@Nullable public static ai.tock.translator.TranslatedSequence translateAndReturnBlankAsNull(StoryHandlerDefinition $this, @Nullable java.lang.CharSequence s)
Translates the specified text and return null if the answer is blank.