Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

<strike>Disclaimer</strike> README

Build Status Coverage Status Code Quality Current Version Python Versions

Despite this code having been in production in quite a heavy use environment for a good few months, I really wouldn’t class it as an example of great code.

It would be fair to say I got sidetracked, and decided to see how much I could abuse certain aspects of Python (such as metaclasses/class creation).

You have been warned!

With that out of the way, telegrambot is pretty easy to get up and running.

% pip install telegrambot
% cat mybot.cfg
[core]
bot_id = <telegram_bot_id>
token = <telegram_bot_token>
[bing]
key = <bing_api_key>
% telegrambot mybot.cfg

As it stands the framework exposes three commands; /crash and /hang were used to test error handling and threading during development whereas /get is a bring-your-own-api-key bing image searcher.

Adding plugins aims to be really easy, just create a namespace package under telegrambot.plugins and subclass telegrambot.plugins.base.BasePlugin (now that I think about it, the namespace package may not be necessary - I will have to re-think my motivation on that one).

Example Plugin

from telegrambot.plugins.base import BasePlugin

# due to annoying limitations class names must be unique
class HelloWorld(BasePlugin):
    # register /hello command to 'hello_handler' method
    commands {'hello': 'hello_handler'}

    def hello_handler(self, args, msg):
        # `args` is a list of the arguments after the command:
        # '/hello world' -> args=['world']
        # `msg` is a dictionary representing the Telegram `Message` object
        # see TelegramAPIMixin for available Telegram API functions
        self.send_message('Hello, {}'.(' '.join(args)),
                          msg['chat']['id'],
                          reply=msg['message_id'])

Metadata

Release files for telegrambot 2.4.0.dev12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for telegrambot 2.4.0.dev12
File Size Uploaded
telegrambot-2.4.0.dev12.tar.gz 22.0 kB Details

Release files / telegrambot-2.4.0.dev12.tar.gz

Download URL telegrambot-2.4.0.dev12.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
76ed6804c9d13f53e257a6ce801e0c301c4670201e5a2418272768bf8c49658b
BLAKE2b-256 checksum
How to use checksums
d0c264ac235f2e9ffd7d1dbaf68c9c071987d867e7fe41c3d663466d238be5b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page