diff --git a/core/automation_engine.py b/core/automation_engine.py index 61774579..c04c1760 100644 --- a/core/automation_engine.py +++ b/core/automation_engine.py @@ -999,6 +999,8 @@ class AutomationEngine: """Send message via Telegram Bot API.""" bot_token = config.get('bot_token', '').strip() chat_id = config.get('chat_id', '').strip() + thread_id = config.get('thread_id', '').strip() + if not bot_token or not chat_id: raise ValueError("Bot token and chat ID are required for Telegram") @@ -1007,9 +1009,16 @@ class AutomationEngine: for key, value in variables.items(): message = message.replace('{' + key + '}', value) + payload = {"chat_id": chat_id, "text": message, "parse_mode": "HTML"} + if thread_id: + try: + payload["message_thread_id"] = int(thread_id) + except ValueError: + pass # invalid — fall back to main chat + resp = requests.post( f'https://api.telegram.org/bot{bot_token}/sendMessage', - json={"chat_id": chat_id, "text": message, "parse_mode": "HTML"}, + json=payload, timeout=10, ) data = resp.json() if resp.status_code == 200 else {} diff --git a/webui/static/stats-automations.js b/webui/static/stats-automations.js index 3586b247..daab421e 100644 --- a/webui/static/stats-automations.js +++ b/webui/static/stats-automations.js @@ -2985,7 +2985,7 @@ function _promptNotifyConfig(groupName) { if (type === 'discord_webhook') { fieldsDiv.innerHTML = ''; } else if (type === 'telegram') { - fieldsDiv.innerHTML = ''; + fieldsDiv.innerHTML = ''; } else if (type === 'pushbullet') { fieldsDiv.innerHTML = ''; } else { @@ -3006,7 +3006,7 @@ function _promptNotifyConfig(groupName) { if (type === 'discord_webhook') { config = { webhook_url: (overlay.querySelector('#deploy-notify-url')?.value || '').trim() }; } else if (type === 'telegram') { - config = { bot_token: (overlay.querySelector('#deploy-notify-token')?.value || '').trim(), chat_id: (overlay.querySelector('#deploy-notify-chat')?.value || '').trim() }; + config = { bot_token: (overlay.querySelector('#deploy-notify-token')?.value || '').trim(), chat_id: (overlay.querySelector('#deploy-notify-chat')?.value || '').trim(), thread_id: (overlay.querySelector('#deploy-notify-thread')?.value || '').trim() }; } else if (type === 'pushbullet') { config = { access_token: (overlay.querySelector('#deploy-notify-token')?.value || '').trim() }; } else { @@ -4138,6 +4138,7 @@ function _renderBlockConfigFields(slotKey, blockType, config) { if (blockType === 'telegram') { const botToken = _escAttr(config.bot_token || ''); const chatId = _escAttr(config.chat_id || ''); + const threadId = _escAttr(config.thread_id || ''); return `
@@ -4146,6 +4147,10 @@ function _renderBlockConfigFields(slotKey, blockType, config) {
+
+ + +
@@ -4525,6 +4530,7 @@ function _readPlacedConfig(slotKey) { return { bot_token: document.getElementById('cfg-' + slotKey + '-bot_token')?.value?.trim() || '', chat_id: document.getElementById('cfg-' + slotKey + '-chat_id')?.value?.trim() || '', + thread_id: document.getElementById('cfg-' + slotKey + '-thread_id')?.value?.trim() || '', message: document.getElementById('cfg-' + slotKey + '-message')?.value || '', }; } diff --git a/webui/static/wishlist-tools.js b/webui/static/wishlist-tools.js index 94e9cd3a..0b4084ad 100644 --- a/webui/static/wishlist-tools.js +++ b/webui/static/wishlist-tools.js @@ -6555,6 +6555,7 @@ const TOOL_HELP_CONTENT = {