Add support for threads
This commit is contained in:
parent
3d0c3cb1c6
commit
d6859ea6b8
2 changed files with 14 additions and 4 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue