From d6859ea6b884921f1cae881bc0aa87405d3df797 Mon Sep 17 00:00:00 2001 From: astra Date: Tue, 3 Sep 2024 18:28:08 +0100 Subject: [PATCH] Add support for threads --- pibooth_telegram_upload.py | 12 +++++++++++- setup.py | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pibooth_telegram_upload.py b/pibooth_telegram_upload.py index 133c173..15d44ae 100644 --- a/pibooth_telegram_upload.py +++ b/pibooth_telegram_upload.py @@ -25,11 +25,12 @@ def pibooth_configure(cfg): """Declare the new configuration options""" cfg.add_option(SECTION, "telegram_token", "", "Telegram Token") cfg.add_option(SECTION, "telegram_chat_id", "", "Telegram chat ID") + cfg.add_option(SECTION, "telegram_thread_id", "", "Telegram thread ID") cfg.add_option( SECTION, "telegram_message", "", - "Message sended on every posted photo", + "Message sent with every posted photo", ) @@ -38,6 +39,7 @@ def pibooth_startup(app, cfg): """Verify Telegram credentials""" telegram_token = cfg.get(SECTION, "telegram_token") telegram_chat_id = cfg.get(SECTION, "telegram_chat_id") + telegram_thread_id = cfg.get(SECTION, "telegram_thread_id") if not telegram_token: LOGGER.error( @@ -51,6 +53,12 @@ def pibooth_startup(app, cfg): + SECTION + "][telegram_chat_id], uploading deactivated" ) + elif not telegram_chat_id: + LOGGER.error( + "Telegram Thread ID not defined in [" + + SECTION + + "][telegram_thread_id], uploading deactivated" + ) else: LOGGER.info("Initializing Telegram client") app.telegram_client = telegram.Bot(token=telegram_token) @@ -61,10 +69,12 @@ def state_processing_exit(app, cfg): """Upload picture to Telegram chat""" if hasattr(app, "telegram_client"): chat_id = cfg.get(SECTION, "telegram_chat_id").strip('"') + thread_id = cfg.get(SECTION, "telegram_thread_id").strip('"') message = cfg.get(SECTION, "telegram_message") try: response = app.telegram_client.send_photo( chat_id=chat_id, + message_thread_id=thread_id, caption=message, photo=open(app.previous_picture_file, 'rb'), parse_mode=telegram.ParseMode.MARKDOWN, diff --git a/setup.py b/setup.py index cefc14f..597fc44 100644 --- a/setup.py +++ b/setup.py @@ -35,8 +35,8 @@ def main(): ], author="Dídac Sabatés", author_email="sabatesduran@gmail.com", - url="https://github.com/sabatesduran/pibooth-telegram-upload", - download_url="https://github.com/sabatesduran/pibooth-telegram-upload/archive/{}.tar.gz".format( + url="https://git.zio.sh/astra/pibooth-telegram-upload", + download_url="https://git.zio.sh/astra/pibooth-telegram-upload/archive/{}.tar.gz".format( plugin.__version__ ), license="GPLv3", @@ -44,7 +44,7 @@ def main(): keywords=["Raspberry Pi", "camera", "photobooth", "telegram", "chat", "bot", "channel"], py_modules=["pibooth_telegram_upload"], python_requires=">=3.6", - install_requires=["pibooth>=2.0.0", "python-telegram-bot==13.12"], + install_requires=["pibooth>=2.0.0", "python-telegram-bot==13.15"], zip_safe=False, # Don't install the lib as an .egg zipfile entry_points={"pibooth": ["pibooth_telegram_upload = pibooth_telegram_upload"]}, )