Class ConversationContext

java.lang.Object
org.teleight.teleightbots.conversation.ConversationContext

public class ConversationContext extends Object
Represents the context of an active conversation between a bot and a user in a specific chat.

This class provides mechanisms to manage the conversation's lifecycle, fetch custom properties, interact with the bot, and capture updates from the user during the conversation.

See Also:
  • Constructor Details

    • ConversationContext

      @Internal protected ConversationContext(@NotNull @NotNull TelegramBot bot, @NotNull @NotNull Chat chat, @NotNull @NotNull User user, @NotNull @NotNull Conversation conversation, @Nullable @Nullable Map<String,Object> properties)
      Constructs a new ConversationContext. Used internally and SHOULD NOT be used elsewhere
      Parameters:
      bot - The bot associated with this conversation.
      chat - The chat associated with this conversation.
      user - The user involved in the conversation.
      conversation - The conversation to be executed.
  • Method Details

    • getProperty

      @Nullable public @Nullable Property<?> getProperty(@NotNull @NotNull String name)
      Gets a property by name.
      Parameters:
      name - The name of the property.
      Returns:
      The property, or null if the property does not exist.
    • getProperties

      public @Unmodifiable Map<String,Property<?>> getProperties()
      Returns:
      A map of all properties applied to the conversation.
    • bot

      public TelegramBot bot()
      Returns:
      The bot associated with this ConversationContext.
    • chat

      public Chat chat()
      Returns:
      The chat associated with this ConversationContext.
    • user

      public User user()
      Returns:
      The user associated with this ConversationContext.
    • conversation

      public Conversation conversation()
      Returns:
      The conversation associated with this ConversationContext.
    • runningConversation

      @Internal protected ConversationContext.ConversationLifecycle runningConversation()
      Used internally and SHOULD NOT be used elsewhere
      Returns:
      The running conversation thread associated with this ConversationContext.
    • waitForUpdate

      @Deprecated @Nullable public @Nullable Update waitForUpdate()
      Waits for an update with no timeout. This is not recommended in most cases
      Returns:
      The update, or null if no update is received.
    • waitForUpdate

      @Nullable public @Nullable Update waitForUpdate(long timeout, @NotNull @NotNull TimeUnit unit)
      Waits for an update with a specified timeout.
      Parameters:
      timeout - The timeout in the specified time unit.
      unit - The time unit of the timeout.
      Returns:
      The update, or null if no update is received within the timeout.