Compare commits

...

6 commits
0.0.3 ... main

Author SHA1 Message Date
61ab083105 Bump version 2024-09-03 18:31:12 +01:00
96783ee268 Oops 2024-09-03 18:29:43 +01:00
d6859ea6b8 Add support for threads 2024-09-03 18:28:08 +01:00
Dídac Sabatés
3d0c3cb1c6 bump 2022-06-13 20:36:54 +02:00
Dídac Sabatés
72207d58f8 fix log 2022-06-13 20:36:19 +02:00
Dídac Sabatés
5bc9459619 bump 2022-06-13 20:26:04 +02:00
2 changed files with 16 additions and 7 deletions

View file

@ -15,7 +15,7 @@ import pibooth
from pibooth.utils import LOGGER
__version__ = "1.0.0"
__version__ = "1.0.3"
SECTION = "Telegram"
@ -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_thread_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,15 +69,16 @@ 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('"')
# upload_path = os.path.basename(app.previous_picture_file)
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,
)
LOGGER.info("File uploaded to Telegram chat: " + response)
LOGGER.info("File uploaded to Telegram chat: " + str(response))
except TelegramError as e:
LOGGER.error(e)

View file

@ -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"]},
)