Back to Blog
TJS (Telebot Host) Advanced TBL

Dynamic Command Handlers in TBL: Handle Any Telegram Update

Dynamic Command Handlers

TBL supports dynamic command handlers for every Telegram update type. Any update (other than messages) can be handled automatically by creating a command following this pattern: /handle_{update_type}.

How It Works

When a specific update type occurs, TBL automatically runs the corresponding /handle_{type} command if it exists.

JAVASCRIPT
/*Command: /handle_chat_member*/
Bot.sendMessage("A chat member update occurred!")

Supported Update Types

This feature works for all update types listed in the Telegram Bot API, including:

  • my_chat_member
  • chat_member
  • chat_join_request
  • business_message
  • edited_business_message
  • poll
  • poll_answer
  • message_reaction
  • message_reaction_count
  • chat_boost
  • removed_chat_boost

Fallback Behavior

If a /handle_{update_type} command is not defined, the update will fall back to /channel_update (for channel-related updates) or * as a universal fallback.

/inline_query

Handles inline mode queries (when users type @yourbot query in Telegram).

JAVASCRIPT
/* Command: /inline_query */
Bot.sendMessage("You searched: " + request.query)

/channel_update

Handles channel posts automatically.

JAVASCRIPT
/* Command: /channel_update */
Bot.sendMessage("New channel post received!")

Example: Welcome Message on User Join

JAVASCRIPT
/* Command: /handle_chat_member */
if (request.new_chat_member && request.new_chat_member.user) {
  Bot.sendMessage("👋 Welcome " + request.new_chat_member.user.first_name + " to the group!")
}

Example: Poll Response Handler

JAVASCRIPT
/* Command: /handle_poll_answer */
Bot.sendMessage("User " + user.first_name + " answered a poll with option: " + request.option_ids)

Best Practices

  • Create handlers only for updates your bot needs
  • Use the * command as a universal fallback for unhandled updates
  • Keep handler commands focused on specific update types
  • Test handlers thoroughly with different update scenarios

📚 Source

This tutorial is based on the official TeleBotHost TBL Documentation. Visit their site for the most up-to-date information and advanced guides.

Share this tutorial