edit telegram_id after initial pr
This commit is contained in:
parent
8450645c52
commit
d47e4ccc0d
3 changed files with 14 additions and 6 deletions
|
|
@ -997,7 +997,8 @@ class AutomationEngine:
|
||||||
"""Send message via Telegram Bot API."""
|
"""Send message via Telegram Bot API."""
|
||||||
bot_token = config.get('bot_token', '').strip()
|
bot_token = config.get('bot_token', '').strip()
|
||||||
chat_id = config.get('chat_id', '').strip()
|
chat_id = config.get('chat_id', '').strip()
|
||||||
thread_id = config.get('thread_id', '').strip()
|
thread_id = str(config.get('thread_id', '')).strip()
|
||||||
|
|
||||||
if not bot_token or not chat_id:
|
if not bot_token or not chat_id:
|
||||||
raise ValueError("Bot token and chat ID are required for Telegram")
|
raise ValueError("Bot token and chat ID are required for Telegram")
|
||||||
|
|
||||||
|
|
@ -1006,9 +1007,16 @@ class AutomationEngine:
|
||||||
for key, value in variables.items():
|
for key, value in variables.items():
|
||||||
message = message.replace('{' + key + '}', value)
|
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(
|
resp = requests.post(
|
||||||
f'https://api.telegram.org/bot{bot_token}/sendMessage',
|
f'https://api.telegram.org/bot{bot_token}/sendMessage',
|
||||||
json={"chat_id": chat_id, "message_thread_id": thread_id, "text": message, "parse_mode": "HTML"},
|
json=payload,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
data = resp.json() if resp.status_code == 200 else {}
|
data = resp.json() if resp.status_code == 200 else {}
|
||||||
|
|
|
||||||
|
|
@ -4315,7 +4315,7 @@ function _promptNotifyConfig(groupName) {
|
||||||
if (type === 'discord_webhook') {
|
if (type === 'discord_webhook') {
|
||||||
config = { webhook_url: (overlay.querySelector('#deploy-notify-url')?.value || '').trim() };
|
config = { webhook_url: (overlay.querySelector('#deploy-notify-url')?.value || '').trim() };
|
||||||
} else if (type === 'telegram') {
|
} else if (type === 'telegram') {
|
||||||
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() };
|
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') {
|
} else if (type === 'pushbullet') {
|
||||||
config = { access_token: (overlay.querySelector('#deploy-notify-token')?.value || '').trim() };
|
config = { access_token: (overlay.querySelector('#deploy-notify-token')?.value || '').trim() };
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -5447,7 +5447,7 @@ function _renderBlockConfigFields(slotKey, blockType, config) {
|
||||||
if (blockType === 'telegram') {
|
if (blockType === 'telegram') {
|
||||||
const botToken = _escAttr(config.bot_token || '');
|
const botToken = _escAttr(config.bot_token || '');
|
||||||
const chatId = _escAttr(config.chat_id || '');
|
const chatId = _escAttr(config.chat_id || '');
|
||||||
const threadID = _escAttr(config.thread_id || '');
|
const threadId = _escAttr(config.thread_id || '');
|
||||||
return `<div class="config-row">
|
return `<div class="config-row">
|
||||||
<label>Bot Token</label>
|
<label>Bot Token</label>
|
||||||
<input type="text" id="cfg-${slotKey}-bot_token" value="${botToken}" placeholder="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11">
|
<input type="text" id="cfg-${slotKey}-bot_token" value="${botToken}" placeholder="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11">
|
||||||
|
|
@ -5458,7 +5458,7 @@ function _renderBlockConfigFields(slotKey, blockType, config) {
|
||||||
</div>
|
</div>
|
||||||
<div class="config-row">
|
<div class="config-row">
|
||||||
<label>Thread ID</label>
|
<label>Thread ID</label>
|
||||||
<input type="text" id="cfg-${slotKey}-thread_id" value="${threadID}" placeholder="Optional integer">
|
<input type="text" id="cfg-${slotKey}-thread_id" value="${threadId}" placeholder="Optional integer">
|
||||||
</div>
|
</div>
|
||||||
<div class="config-row">
|
<div class="config-row">
|
||||||
<label>Message</label>
|
<label>Message</label>
|
||||||
|
|
|
||||||
|
|
@ -6530,7 +6530,7 @@ const TOOL_HELP_CONTENT = {
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>Bot Token:</strong> Your Telegram bot token (from @BotFather)</li>
|
<li><strong>Bot Token:</strong> Your Telegram bot token (from @BotFather)</li>
|
||||||
<li><strong>Chat ID:</strong> The chat/group ID to send messages to</li>
|
<li><strong>Chat ID:</strong> The chat/group ID to send messages to</li>
|
||||||
<li><strong>Thread ID:</strong> Thread ID</li>
|
<li><strong>Thread ID:</strong> Optional — only set if your group uses Telegram topics. Leave blank for the main chat.</li>
|
||||||
<li><strong>Message Template:</strong> Custom message with variable placeholders</li>
|
<li><strong>Message Template:</strong> Custom message with variable placeholders</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue