Use the core.plugin.handler decorator to register functions as handlers. There are two ways to do this:
- Generic approach: Pass the handler class (e.g.,
CommandHandler) as the first argument, followed by the handler's configuration parameters. - Sub-decorator approach: Use specific helper decorators like
@handler.command() for a more concise syntax.
from core.plugin import Plugin, handler
from telegram import Update
from telegram.ext import CommandHandler, CallbackContext
class TestPlugin(Plugin):
# Generic approach
@handler(CommandHandler, command='start', block=False)
async def start(self, update: Update, context: CallbackContext):
await update.effective_chat.send_message('hello world!')
# Sub-decorator approach
@handler.command(command='help', block=False)
async def help_command(self, update: Update, context: CallbackContext):
await update.effective_chat.send_message('Help text')