Merge pull request #594 from Skowll/telegram_thread_id
Add Telegram thread
This commit is contained in:
commit
58d0657fe5
3 changed files with 19 additions and 3 deletions
|
|
@ -999,6 +999,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()
|
||||||
|
|
||||||
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")
|
||||||
|
|
||||||
|
|
@ -1007,9 +1009,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, "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 {}
|
||||||
|
|
|
||||||
|
|
@ -2985,7 +2985,7 @@ function _promptNotifyConfig(groupName) {
|
||||||
if (type === 'discord_webhook') {
|
if (type === 'discord_webhook') {
|
||||||
fieldsDiv.innerHTML = '<input id="deploy-notify-url" type="text" placeholder="Discord Webhook URL" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;">';
|
fieldsDiv.innerHTML = '<input id="deploy-notify-url" type="text" placeholder="Discord Webhook URL" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;">';
|
||||||
} else if (type === 'telegram') {
|
} else if (type === 'telegram') {
|
||||||
fieldsDiv.innerHTML = '<input id="deploy-notify-token" type="text" placeholder="Bot Token" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;"><input id="deploy-notify-chat" type="text" placeholder="Chat ID" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;">';
|
fieldsDiv.innerHTML = '<input id="deploy-notify-token" type="text" placeholder="Bot Token" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;"><input id="deploy-notify-chat" type="text" placeholder="Chat ID" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;"><input id="deploy-notify-thread" type="text" placeholder="Thread ID" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;">';
|
||||||
} else if (type === 'pushbullet') {
|
} else if (type === 'pushbullet') {
|
||||||
fieldsDiv.innerHTML = '<input id="deploy-notify-token" type="text" placeholder="Access Token" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;">';
|
fieldsDiv.innerHTML = '<input id="deploy-notify-token" type="text" placeholder="Access Token" style="width:100%;padding:9px 12px;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);border-radius:8px;color:#fff;font-size:0.88em;margin-top:6px;box-sizing:border-box;">';
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -3006,7 +3006,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() };
|
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 {
|
||||||
|
|
@ -4138,6 +4138,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 || '');
|
||||||
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">
|
||||||
|
|
@ -4146,6 +4147,10 @@ function _renderBlockConfigFields(slotKey, blockType, config) {
|
||||||
<label>Chat ID</label>
|
<label>Chat ID</label>
|
||||||
<input type="text" id="cfg-${slotKey}-chat_id" value="${chatId}" placeholder="-1001234567890 or @channelname">
|
<input type="text" id="cfg-${slotKey}-chat_id" value="${chatId}" placeholder="-1001234567890 or @channelname">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="config-row">
|
||||||
|
<label>Thread ID</label>
|
||||||
|
<input type="text" id="cfg-${slotKey}-thread_id" value="${threadId}" placeholder="Optional integer">
|
||||||
|
</div>
|
||||||
<div class="config-row">
|
<div class="config-row">
|
||||||
<label>Message</label>
|
<label>Message</label>
|
||||||
<textarea id="cfg-${slotKey}-message" placeholder="Message with {variables}...">${config.message || '{name} completed with status: {status}'}</textarea>
|
<textarea id="cfg-${slotKey}-message" placeholder="Message with {variables}...">${config.message || '{name} completed with status: {status}'}</textarea>
|
||||||
|
|
@ -4525,6 +4530,7 @@ function _readPlacedConfig(slotKey) {
|
||||||
return {
|
return {
|
||||||
bot_token: document.getElementById('cfg-' + slotKey + '-bot_token')?.value?.trim() || '',
|
bot_token: document.getElementById('cfg-' + slotKey + '-bot_token')?.value?.trim() || '',
|
||||||
chat_id: document.getElementById('cfg-' + slotKey + '-chat_id')?.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 || '',
|
message: document.getElementById('cfg-' + slotKey + '-message')?.value || '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6555,6 +6555,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> 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