@@ -200,6 +200,8 @@ def load_config_file(path: Path | None) -> dict[str, Any]:
200200 "gotify_priority" : notifications .get ("gotify_priority" ),
201201 "telegram_bot_token" : notifications .get ("telegram_bot_token" ),
202202 "telegram_chat_id" : notifications .get ("telegram_chat_id" ),
203+ "telegram_group_id" : notifications .get ("telegram_group_id" ),
204+ "telegram_topic_id" : notifications .get ("telegram_topic_id" ),
203205 "notification_timeout" : notifications .get ("timeout" ),
204206 "notification_retries" : notifications .get ("retries" ),
205207 "notification_verify_tls" : notifications .get ("verify_tls" ),
@@ -260,6 +262,8 @@ def build_parser() -> argparse.ArgumentParser:
260262 parser .add_argument ("--gotify-priority" , type = int , default = None , help = "Gotify priority" )
261263 parser .add_argument ("--telegram-bot-token" , default = None , help = "Telegram bot token" )
262264 parser .add_argument ("--telegram-chat-id" , default = None , help = "Telegram user/chat id" )
265+ parser .add_argument ("--telegram-group-id" , default = None , help = "Telegram group or supergroup id" )
266+ parser .add_argument ("--telegram-topic-id" , type = int , default = None , help = "Telegram forum topic id" )
263267 parser .add_argument ("--notification-timeout" , type = float , default = None , help = "Notification HTTP timeout in seconds" )
264268 parser .add_argument ("--notification-retries" , type = int , default = None , help = "Notification retry count" )
265269
@@ -447,6 +451,13 @@ def load_config(args: argparse.Namespace, environ: Mapping[str, str] | None = No
447451 telegram_chat_id = str (
448452 _first (args .telegram_chat_id , _env_value (env , "STOPLIGA_TELEGRAM_CHAT_ID" ), file_cfg .get ("telegram_chat_id" ), DEFAULTS .telegram_chat_id )
449453 ) if _first (args .telegram_chat_id , _env_value (env , "STOPLIGA_TELEGRAM_CHAT_ID" ), file_cfg .get ("telegram_chat_id" ), DEFAULTS .telegram_chat_id ) is not None else None ,
454+ telegram_group_id = str (
455+ _first (args .telegram_group_id , _env_value (env , "STOPLIGA_TELEGRAM_GROUP_ID" ), file_cfg .get ("telegram_group_id" ), DEFAULTS .telegram_group_id )
456+ ) if _first (args .telegram_group_id , _env_value (env , "STOPLIGA_TELEGRAM_GROUP_ID" ), file_cfg .get ("telegram_group_id" ), DEFAULTS .telegram_group_id ) is not None else None ,
457+ telegram_topic_id = _parse_int (
458+ _first (args .telegram_topic_id , _env_value (env , "STOPLIGA_TELEGRAM_TOPIC_ID" ), file_cfg .get ("telegram_topic_id" )),
459+ field_name = "telegram_topic_id" ,
460+ ) if _first (args .telegram_topic_id , _env_value (env , "STOPLIGA_TELEGRAM_TOPIC_ID" ), file_cfg .get ("telegram_topic_id" )) is not None else None ,
450461 notification_timeout = _parse_float (
451462 _first (args .notification_timeout , _env_value (env , "STOPLIGA_NOTIFICATION_TIMEOUT" ), file_cfg .get ("notification_timeout" ), DEFAULTS .notification_timeout ),
452463 field_name = "notification_timeout" ,
@@ -509,8 +520,17 @@ def validate_config(config: Config, *, validate_connection: bool) -> None:
509520 raise ConfigError ("Automatic route creation requires both STOPLIGA_VPN_NAME and STOPLIGA_TARGETS" )
510521 if bool (config .gotify_url ) != bool (config .gotify_token ):
511522 raise ConfigError ("Gotify notifications require both STOPLIGA_GOTIFY_URL and STOPLIGA_GOTIFY_TOKEN" )
512- if bool (config .telegram_bot_token ) != bool (config .telegram_chat_id ):
513- raise ConfigError ("Telegram notifications require both STOPLIGA_TELEGRAM_BOT_TOKEN and STOPLIGA_TELEGRAM_CHAT_ID" )
523+ if config .telegram_chat_id and config .telegram_group_id :
524+ raise ConfigError ("Set either STOPLIGA_TELEGRAM_CHAT_ID or STOPLIGA_TELEGRAM_GROUP_ID, not both" )
525+ telegram_target = config .resolved_telegram_chat_id ()
526+ if bool (config .telegram_bot_token ) != bool (telegram_target ):
527+ raise ConfigError (
528+ "Telegram notifications require STOPLIGA_TELEGRAM_BOT_TOKEN and either STOPLIGA_TELEGRAM_CHAT_ID or STOPLIGA_TELEGRAM_GROUP_ID"
529+ )
530+ if config .telegram_topic_id is not None and not telegram_target :
531+ raise ConfigError ("STOPLIGA_TELEGRAM_TOPIC_ID requires STOPLIGA_TELEGRAM_GROUP_ID or STOPLIGA_TELEGRAM_CHAT_ID" )
532+ if config .telegram_topic_id is not None and config .telegram_topic_id <= 0 :
533+ raise ConfigError ("STOPLIGA_TELEGRAM_TOPIC_ID must be > 0" )
514534 if validate_connection :
515535 _validate_unifi_host (config .host or "" )
516536 if config .gotify_url :
0 commit comments