public class StoryHandlerDefinitionBase<T extends ConnectorStoryHandlerBase<?>> implements BotBus, StoryHandlerDefinition
Base implementation of interface StoryHandlerDefinition.
interface StoryHandlerDefinitionpublic static ai.tock.bot.definition.StoryHandlerDefinitionBase.Companion Companion
public StoryHandlerDefinitionBase(@NotNull
BotBus bus)
Base implementation of interface StoryHandlerDefinition.
interface StoryHandlerDefinitionpublic void answer()
The method to implement if there is no interface StoryStep in the interface StoryDefinition
or when current interface StoryStep is null
public void handle()
Default implementation redirect to answer.
@NotNull public ConnectorType getConnectorType()
Shortcut for BotBus.targetConnectorType.
@Nullable
public T findConnector(@NotNull
ConnectorType connectorType)
Method to override in order to provide interface ConnectorStoryHandler.
Default implementation use annotations annotated with @annotationclass ConnectorHandler.
@Nullable
public T findConnector(@NotNull
java.lang.String connectorId)
Method to override in order to provide interface ConnectorStoryHandler.
Default implementation use annotations annotated with @annotationclass ConnectorIdHandlers.
@Nullable public T getConnector()
Provides the current interface ConnectorStoryHandler using findConnector.
interface ConnectorStoryHandler,
findConnector@NotNull public T getC()
Provides a not null connector. Throws NPE if connector is null.
@NotNull public BotBus getBus()
@NotNull public Action getAction()
The user action.
@NotNull public java.lang.String getApplicationId()
The current application id.
@NotNull public BotDefinition getBotDefinition()
The bot definition of the current bot.
@NotNull public PlayerId getBotId()
The current bot id.
@NotNull public ConnectorData getConnectorData()
The data specific to the connector (if any).
@Nullable public java.lang.String getContextId()
The current context identifier.
public int getCurrentAnswerIndex()
The current answer index of the bot for this action.
@NotNull public Dialog getDialog()
The current dialog history for this user.
@NotNull public java.util.Map<java.lang.String,ai.tock.bot.engine.dialog.EntityStateValue> getEntities()
The entities in the dialog state.
@NotNull public ai.tock.translator.I18nKeyProvider getI18nProvider()
To manage i18n.
public void setI18nProvider(@NotNull
ai.tock.translator.I18nKeyProvider p)
To manage i18n.
@Nullable public IntentAware getIntent()
The current intent.
@Nullable public NextUserActionState getNextUserActionState()
Qualify the next user action.
public void setNextUserActionState(@Nullable
NextUserActionState p)
Qualify the next user action.
@Nullable public StoryStep<? extends ai.tock.bot.definition.StoryHandlerDefinition> getStep()
public void setStep(@Nullable
StoryStep<? extends ai.tock.bot.definition.StoryHandlerDefinition> step)
@Nullable public java.lang.String getStepName()
The name of the step if any.
@NotNull public Story getStory()
The current story.
public void setStory(@NotNull
Story p)
The current story.
@NotNull public ConnectorType getTargetConnectorType()
The class ConnectorType used for the response.
class ConnectorTypepublic boolean getTest()
Is it a test mode ?
@NotNull public Connector getUnderlyingConnector()
The underlying interface Connector used.
Please do not use this method as it is exposed for third party libraries only.
interface Connector@NotNull public PlayerId getUserId()
The current user id.
@NotNull public ai.tock.translator.UserInterfaceType getUserInterfaceType()
The current user interface type.
@NotNull public java.util.Locale getUserLocale()
The current user Locale.
@NotNull public UserPreferences getUserPreferences()
User preferences of the current user.
@Nullable public java.lang.String getUserText()
The text sent by the user if any.
@NotNull public UserTimeline getUserTimeline()
The user timeline. Gets history and data about the user.
public boolean booleanChoice(@NotNull
ParameterKey key)
Returns true if the specified choice parameter has the "true" value, false either.
public void changeContextValue(@NotNull
ParameterKey key,
@Nullable
java.lang.Object value)
Updates persistent context value.
public void changeContextValue(@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 void changeEntityText(@NotNull
ai.tock.nlp.api.client.model.Entity entity,
@Nullable
java.lang.String textContent)
Updates the current entity text value in the dialog.
entity - the entity definitiontextContent - the new entity text contentpublic void changeEntityValue(@NotNull
ai.tock.nlp.api.client.model.Entity entity,
@NotNull
EntityValue newValue)
Updates the current entity value in the dialog.
entity - the entity definitionnewValue - the new entity valuepublic void changeEntityValue(@NotNull
ai.tock.nlp.api.client.model.Entity entity,
@Nullable
ai.tock.nlp.entity.Value newValue)
Updates the current entity value in the dialog.
entity - the entity definitionnewValue - the new entity valuepublic void changeEntityValue(@NotNull
java.lang.String role,
@Nullable
EntityValue newValue)
Updates the current entity value in the dialog.
role - entity rolenewValue - the new entity value@Nullable
public java.lang.String choice(@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 SendChoice@Nullable
public <T> T contextValue(@NotNull
ParameterKey key)
Returns the persistent current context value.
@Nullable
public <T> T contextValue(@NotNull
java.lang.String name)
Returns the persistent current context value.
public long defaultDelay(int answerIndex)
Get the default delay between two answers.
@NotNull public BotBus end(@NotNull Action action, long delay)
Sends class Action as last bot answer.
class Action@NotNull public BotBus end(@NotNull Message message, long delay)
Sends interface Message as last bot answer.
interface Message@NotNull public BotBus end(@NotNull MessagesList messages, long initialDelay)
Sends a class MessagesList and end the dialog.
class MessagesList@NotNull public BotBus end(@NotNull java.lang.CharSequence i18nText, @NotNull java.lang.Object... i18nArgs)
Sends i18nText as last bot answer.
@NotNull public BotBus end(@NotNull java.lang.CharSequence i18nText, long delay, @NotNull java.lang.Object... i18nArgs)
Sends i18nText as last bot answer.
@NotNull public BotBus end(long delay)
Send previously registered interface ConnectorMessage as last bot answer.
interface ConnectorMessage@NotNull public BotBus end(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 BotBus endRawText(@Nullable java.lang.CharSequence plainText, long delay)
Sends text that should not be translated as last bot answer.
@Nullable
public java.lang.String entityText(@NotNull
ai.tock.nlp.api.client.model.Entity entity)
Returns the current text content for the specified entity.
@Nullable
public java.lang.String entityText(@NotNull
java.lang.String role)
Returns the current text content for the specified entity.
@Nullable public <T extends Value> T entityValue(@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 <T extends Value> T entityValue(@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 EntityValue entityValueDetails(@NotNull ai.tock.nlp.api.client.model.Entity entity)
Returns the current class EntityValue for the specified entity.
class EntityValue@Nullable public EntityValue entityValueDetails(@NotNull java.lang.String role)
Returns the current class EntityValue for the specified role.
class EntityValue@Nullable
public <T> T getBusContextValue(@NotNull
ParameterKey key)
Returns the non persistent current context value. Bus context values are useful to store a temporary (ie request scoped) state.
@Nullable
public <T> T getBusContextValue(@NotNull
java.lang.String name)
Returns the non persistent current context value. Bus context values are useful to store a temporary (ie request scoped) state.
public void handleAndSwitchStory(@NotNull
StoryDefinition storyDefinition,
@NotNull
Intent starterIntent)
Handles the action and switches the context to the specified story definition.
public boolean hasActionEntity(@NotNull
ai.tock.nlp.api.client.model.Entity entity)
Returns true if the current action has the specified entity role.
public boolean hasActionEntity(@NotNull
java.lang.String role)
Returns true if the current action has the specified entity role.
public boolean hasChoiceValue(@NotNull
ParameterKey param,
@NotNull
ParameterKey value)
Checks that the specified choice parameter has the specified value.
@NotNull
public ai.tock.translator.I18nLabelValue i18n(@NotNull
java.lang.CharSequence defaultLabel,
@NotNull
java.lang.Object... args)
@NotNull
public ai.tock.translator.I18nLabelValue i18n(@NotNull
java.lang.CharSequence defaultLabel,
@NotNull
java.util.List<? extends java.lang.Object> args)
@NotNull
public ai.tock.translator.I18nLabelValue i18nKey(@NotNull
java.lang.String key,
@NotNull
java.lang.CharSequence defaultLabel,
@NotNull
java.lang.Object... args)
Gets an i18n label with the specified key.
public boolean isChoiceAction()
Is this current action is a class SendChoice?
class SendChoicepublic boolean isFeatureEnabled(@NotNull
FeatureType feature,
boolean p)
Is the feature enabled?
feature - the feature to checkp - the default value if the feature state is unknownpublic boolean isIntent(@NotNull
IntentAware intentOwner)
To know if the current intent is owned by the interface IntentAware.
interface IntentAwarepublic void markAsUnknown()
Marks the current as not understood in the nlp model.
@Nullable public NlpCallStats nlpStats()
Returns the NLP call stats if an NLP call has occurred, null either.
public void reloadProfile()
Reloads the user profile.
public void removeAllEntityValues()
Removes all current entity values.
public void removeEntityValue(@NotNull
ai.tock.nlp.api.client.model.Entity entity)
Removes entity value for the specified role.
public void removeEntityValue(@NotNull
java.lang.String role)
Removes entity value for the specified role.
public void resetDialogState()
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.
@NotNull public BotBus send(@NotNull Action action, long delay)
Sends an class Action.
class Action@NotNull public BotBus send(@NotNull Message message, long delay)
Sends a interface Message.
interface Message@NotNull public BotBus send(@NotNull MessagesList messages, long initialDelay)
Sends a class MessagesList.
class MessagesList@NotNull public BotBus send(@NotNull java.lang.CharSequence i18nText, @NotNull java.lang.Object... i18nArgs)
Sends i18nText.
@NotNull public BotBus send(@NotNull java.lang.CharSequence i18nText, long delay, @NotNull java.lang.Object... i18nArgs)
Sends i18nText.
@NotNull public BotBus send(long delay)
Sends previously registered interface ConnectorMessage.
interface ConnectorMessage@NotNull public BotBus send(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 BotBus sendRawText(@Nullable java.lang.CharSequence plainText, long delay)
Send text that should not be translated.
public void setBusContextValue(@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.
public void setBusContextValue(@NotNull
java.lang.String 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.
public void skipAnswer()
Does not send an answer. Synchronous interface Connectors (like Google Assistant or Alexa)
usually do not support skipping answer.
interface Connectorpublic void switchStory(@NotNull
StoryDefinition storyDefinition,
@NotNull
Intent starterIntent)
Switches the context to the specified story definition (start a new class Story).
class Story@NotNull
public ai.tock.translator.TranslatedSequence translate(@Nullable
ai.tock.translator.I18nLabelValue key)
Translates the specified key.
@NotNull
public ai.tock.translator.TranslatedSequence translate(@Nullable
java.lang.CharSequence text,
@NotNull
java.lang.Object... args)
Translates and format if needed the text with the optionals args.
@Nullable
public ai.tock.translator.TranslatedSequence translateAndReturnBlankAsNull(@Nullable
java.lang.CharSequence s)
Translates the specified text and return null if the answer is blank.
@NotNull public BotBus withMessage(@NotNull ConnectorMessage message)
Adds the specified interface ConnectorMessage to the bus context if the targetConnectorType is compatible.
interface ConnectorMessage,
targetConnectorType@NotNull public BotBus withMessage(@NotNull ConnectorType connectorType, @NotNull kotlin.jvm.functions.Function0<? extends ai.tock.bot.connector.ConnectorMessage> messageProvider)
Adds the specified interface ConnectorMessage to the bus context if the targetConnectorType is compatible.
interface ConnectorMessage,
targetConnectorType@NotNull public BotBus withMessage(@NotNull ConnectorType connectorType, @NotNull java.lang.String connectorId, @NotNull kotlin.jvm.functions.Function0<? extends ai.tock.bot.connector.ConnectorMessage> messageProvider)
Adds the specified interface ConnectorMessage to the bus context if the targetConnectorType and connectorId is compatible.
interface ConnectorMessage,
targetConnectorType,
connectorId@NotNull public BotBus withNotificationType(@NotNull ActionNotificationType notificationType)
Adds the specified enum ActionNotificationType to the bus context.
enum ActionNotificationType@NotNull public BotBus withPriority(@NotNull ActionPriority priority)
Adds the specified enum ActionPriority to the bus context.
enum ActionPriority@NotNull public BotBus withVisibility(@NotNull ActionVisibility visibility)
Adds the specified enum ActionVisibility to the bus context.
enum ActionVisibility