Annotation Interface ChannelPostHandler


@Retention(RUNTIME) @Target(METHOD) @Repeatable(ChannelPostHandlers.class) public @interface ChannelPostHandler
Annotation for handling incoming channel posts in a declarative manner. Specifically designed for filtering and handling messages posted in channels.

Basic command handler example for channels:


 @ChannelPostHandler(commands = "announce")
 void handleAnnounceCommand(BotContext context, Message message) {
     // Handle /announce command in channel posts
 }
 

Media post example:


 @ChannelPostHandler(type = {MessageType.PHOTO, MessageType.VIDEO})
 void handleChannelMedia(BotContext context, Message message) {
     // Handle both photo and video posts in channels
 }
 

Advanced example with text matching:


 @ChannelPostHandler(texts = {"news", "update"})
 void handleImportantUpdates(BotContext context, Message message) {
     // Handle text posts containing "news" or "update" with "important" prefix
 }
 


Equivalent with using BotClient.onChannelPost(FilterExecutor, UpdateHandler)
Since:
1.2.0
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Specifies the bot commands to match in channel posts (e.g., "/announce", "/news").
    Class<? extends CustomFilter>
    Custom filter class for advanced filtering logic beyond the built-in options.
    int
    Priority order for handler registration and execution.
    Regular expression pattern to match against channel post text content.
    Specifies exact text content to match in the channel post.
    Specifies the message types to match in channel posts (text, photo, video, etc.).
  • Element Details

    • commands

      String[] commands
      Specifies the bot commands to match in channel posts (e.g., "/announce", "/news"). Multiple commands are combined using OR logic - the handler will trigger if the channel post contains any of the specified commands.
      Returns:
      array of command strings to match
      Default:
      {}
    • texts

      String[] texts
      Specifies exact text content to match in the channel post. Multiple texts are combined using OR logic - the handler will trigger if the channel post text exactly matches any of the specified strings.
      Returns:
      array of exact text strings to match
      Default:
      {}
    • regex

      String regex
      Regular expression pattern to match against channel post text content. The handler will trigger if the channel post text matches the specified regex pattern.
      Returns:
      regex pattern string for channel post text matching
      Default:
      ""
    • type

      MessageType[] type
      Specifies the message types to match in channel posts (text, photo, video, etc.). Multiple message types are combined using OR logic - the handler will trigger if the channel post type matches any of the specified types.
      Returns:
      array of MessageType enum values to filter by
      Default:
      {}
    • filter

      Class<? extends CustomFilter> filter
      Custom filter class for advanced filtering logic beyond the built-in options. Use this when you need complex or application-specific filtering conditions for channel posts that cannot be expressed through the other annotation parameters.
      Returns:
      class implementing CustomFilter interface
      Default:
      io.github.natanimn.telebof.filters.DefaultCustomFilter.class
    • priority

      int priority
      Priority order for handler registration and execution. Handlers with lower priority numbers are registered and executed before those with higher numbers. This allows controlling the order of handler processing when multiple handlers could match the same channel post.
      Returns:
      priority integer value (lower = earlier execution)
      Default:
      0