Annotation Interface MessageHandler
@Retention(RUNTIME)
@Target(METHOD)
@Repeatable(MessageHandlers.class)
public @interface MessageHandler
Annotation for handling incoming messages in a declarative manner.
 Provides a convenient alternative to programmatic message registration using
 
BotClient.onMessage(FilterExecutor, UpdateHandler).
 Basic command handler example:
 @MessageHandler(commands = "start")
 void handleStartCommand(BotContext context, Message message) {
     // Handle /start command
 }
 
 bot.onMessage(filter -> filter.commands("start"), (ctx, message) -> {});
 Advanced example with multiple filters:
 @MessageHandler(
     commands = {"help", "support"},
     chatType = ChatType.PRIVATE,
     state = "awaiting_help"
 )
 void handlePrivateHelp(BotContext context, Message message) {
     // Handle private text messages with commands /help or /support
     // matching specific conversation state
 }
 
 bot.onMessage(filter ->
     (filter.commands("help") || filter.commands("support")) &&
     filter.Private() &&
     filter.state("awaiting_help"),
     (ctx, message) -> {}
 );
 Media message example:
 @MessageHandler(type = {MessageType.PHOTO, MessageType.VIDEO})
 void handleMediaMessages(BotContext context, Message message) {
     // Handle both photo and video messages
 }
 - Since:
- 1.2.0
- See Also:
- 
Optional Element SummaryOptional ElementsModifier and TypeOptional ElementDescriptionChatType[]Specifies the chat types where this message handler should be active.String[]Specifies the bot commands to match (e.g., "/start", "/help").Class<? extends CustomFilter> Custom filter class for advanced filtering logic beyond the built-in options.intPriority order for handler registration and execution.Regular expression pattern to match against message text content.Conversation state required for this message handler to trigger.String[]Specifies exact text content to match in the message.Specifies the message types to match (text, photo, video, etc.).
- 
Element Details- 
commandsString[] commandsSpecifies the bot commands to match (e.g., "/start", "/help"). Multiple commands are combined using OR logic - the handler will trigger if the message contains any of the specified commands.- Returns:
- array of command strings to match
 - Default:
- {}
 
- 
textsString[] textsSpecifies exact text content to match in the message. Multiple texts are combined using OR logic - the handler will trigger if the message text exactly matches any of the specified strings.- Returns:
- array of exact text strings to match
 - Default:
- {}
 
- 
chatType
- 
regexString regexRegular expression pattern to match against message text content. The handler will trigger if the message text matches the specified regex pattern.- Returns:
- regex pattern string for message text matching
 - Default:
- ""
 
- 
typeMessageType[] typeSpecifies the message types to match (text, photo, video, etc.). Multiple message types are combined using OR logic - the handler will trigger if the message type matches any of the specified types.- Returns:
- array of MessageTypeenum values to filter by
 - Default:
- {}
 
- 
filterClass<? extends CustomFilter> filterCustom filter class for advanced filtering logic beyond the built-in options. Use this when you need complex or application-specific filtering conditions that cannot be expressed through the other annotation parameters.- Returns:
- class implementing CustomFilterinterface
 - Default:
- io.github.natanimn.telebof.filters.DefaultCustomFilter.class
 
- 
stateString stateConversation state required for this message handler to trigger. The handler will only be invoked if the current conversation state matches the specified state value.- Returns:
- required conversation state string
 - Default:
- ""
 
- 
priorityint priorityPriority 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 message.- Returns:
- priority integer value (lower = earlier execution)
 - Default:
- 0
 
 
-