Skip to main content

A simple plugin system for pyTelegramBotAPI (telebot)

Project description

TeleBot Plugins

A simple plugin system for pyTelegramBotAPI (telebot) that allows you to organize your bot's functionality into separate plugin files without having to redefine the bot instance in each file.

Features

  • Load plugins from a specified directory
  • Support for both synchronous and asynchronous telebot
  • Handle relative paths properly
  • Automatically register the bot instance globally
  • Support for webhook and polling modes

Installation

pip install telebot-plugins

Usage

Basic Example

from telebot import TeleBot
from telebot_plugins import TelebotWithPlugins

# Create a bot instance
API_TOKEN = "YOUR_BOT_TOKEN"
bot = TeleBot(API_TOKEN)

# Initialize TelebotWithPlugins
plugins = TelebotWithPlugins(
    bot=bot,
    plugins="plugins",  # plugins folder name
    exclude=["disabled_plugin.py"]  # files to exclude (optional)
)

if __name__ == '__main__':
    # Start the bot
    bot.polling()

Example Plugin File (plugins/example.py)

from telebot import bot  # The bot is automatically available

@bot.message_handler(commands=['start'])
def send_welcome(message):
    bot.reply_to(message, "Hello! This is a plugin example.")

Async Bot Example

from telebot.async_telebot import AsyncTeleBot
from telebot_plugins import TelebotWithPlugins
import asyncio

# Create an async bot instance
API_TOKEN = "YOUR_BOT_TOKEN"
bot = AsyncTeleBot(API_TOKEN)

# Initialize TelebotWithPlugins
plugins = TelebotWithPlugins(
    bot=bot,
    plugins="plugins"
)

if __name__ == '__main__':
    # Start the async bot
    asyncio.run(bot.polling())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telebot_plugins-0.1.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telebot_plugins-0.1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file telebot_plugins-0.1.0.tar.gz.

File metadata

  • Download URL: telebot_plugins-0.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for telebot_plugins-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1682e7dd4e3da49def7349e638c27f6d62bbfe38d2e9a147c273caf8ecf84a05
MD5 fbc4d5a97de0178a4e502a2cdc2277f4
BLAKE2b-256 2343256f984fb305b8553dee4caf782941c9891ee5c6dc9d2808b9651d0bc18e

See more details on using hashes here.

File details

Details for the file telebot_plugins-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for telebot_plugins-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73671fb4f754aa3fed2d56570645c557b87fcf7da2c4685386a236b7e7be6c71
MD5 403bff81fed9c5c656062b03df0106cf
BLAKE2b-256 a05fdad1f3b8c59bcb4bbb75f51ebebd8a3bdbf5d3f43434187658e5fee3cb57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page