Add allowed chat IDs filter to Telegram Commands
New input `allowed_chat_ids` restricts which Telegram chats can trigger the automation. Leave empty to allow all chats (no filtering). Useful for security-sensitive commands. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,16 @@ Commands should start with "/" (e.g., `/status`, `/lights_on`, `/arm_alarm`). Th
|
|||||||
|
|
||||||
Each command has its own callback action that executes when received.
|
Each command has its own callback action that executes when received.
|
||||||
|
|
||||||
|
## Access Control
|
||||||
|
|
||||||
|
You can restrict which Telegram chats are allowed to trigger the automation by specifying **Allowed Chat IDs**:
|
||||||
|
|
||||||
|
- Leave empty to allow commands from any chat (no filtering)
|
||||||
|
- Add specific chat IDs to restrict access to those chats only
|
||||||
|
- Supports user IDs (positive numbers) and group IDs (negative numbers)
|
||||||
|
|
||||||
|
This is useful for security-sensitive commands like arming alarms or controlling locks.
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
Alexei Dolgolyov (dolgolyov.alexei@gmail.com)
|
Alexei Dolgolyov (dolgolyov.alexei@gmail.com)
|
||||||
|
|||||||
@@ -11,6 +11,24 @@ blueprint:
|
|||||||
domain: automation
|
domain: automation
|
||||||
|
|
||||||
input:
|
input:
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
# Access Control
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
access_group:
|
||||||
|
name: "Access Control"
|
||||||
|
collapsed: true
|
||||||
|
input:
|
||||||
|
allowed_chat_ids:
|
||||||
|
name: Allowed Chat IDs
|
||||||
|
description: >
|
||||||
|
List of Telegram chat IDs allowed to trigger this automation.
|
||||||
|
Leave empty to allow all chat IDs (no filtering).
|
||||||
|
Can be user IDs (positive) or group IDs (negative).
|
||||||
|
default: []
|
||||||
|
selector:
|
||||||
|
text:
|
||||||
|
multiple: true
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
# Command Configuration
|
# Command Configuration
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
@@ -120,6 +138,7 @@ variables:
|
|||||||
# Input references
|
# Input references
|
||||||
commands: !input commands
|
commands: !input commands
|
||||||
answers: !input answers
|
answers: !input answers
|
||||||
|
allowed_chat_ids: !input allowed_chat_ids
|
||||||
|
|
||||||
# Callback references (needed for condition checks)
|
# Callback references (needed for condition checks)
|
||||||
command_1_callback: !input command_1_callback
|
command_1_callback: !input command_1_callback
|
||||||
@@ -136,6 +155,10 @@ variables:
|
|||||||
chat_id: "{{ trigger.event.data.chat_id | default('') }}"
|
chat_id: "{{ trigger.event.data.chat_id | default('') }}"
|
||||||
user_id: "{{ trigger.event.data.user_id | default('') }}"
|
user_id: "{{ trigger.event.data.user_id | default('') }}"
|
||||||
|
|
||||||
|
# Check if chat ID is allowed (empty list = allow all)
|
||||||
|
is_chat_allowed: >
|
||||||
|
{{ allowed_chat_ids | length == 0 or (chat_id | string) in allowed_chat_ids }}
|
||||||
|
|
||||||
# Find the index of the received command in our list
|
# Find the index of the received command in our list
|
||||||
# Returns -1 if command not found or callback is empty
|
# Returns -1 if command not found or callback is empty
|
||||||
command_index: >
|
command_index: >
|
||||||
@@ -151,11 +174,11 @@ variables:
|
|||||||
is_debug: false
|
is_debug: false
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Condition - Only proceed if we received a valid command
|
# Condition - Only proceed if we received a valid command from allowed chat
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
condition:
|
condition:
|
||||||
- condition: template
|
- condition: template
|
||||||
value_template: "{{ received_command != '' and command_index >= 0 }}"
|
value_template: "{{ received_command != '' and command_index >= 0 and is_chat_allowed }}"
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Actions
|
# Actions
|
||||||
@@ -176,10 +199,12 @@ action:
|
|||||||
Received command: {{ received_command }}
|
Received command: {{ received_command }}
|
||||||
Chat ID: {{ chat_id }}
|
Chat ID: {{ chat_id }}
|
||||||
User ID: {{ user_id }}
|
User ID: {{ user_id }}
|
||||||
|
Chat allowed: {{ is_chat_allowed }}
|
||||||
|
|
||||||
Command index: {{ command_index }}
|
Command index: {{ command_index }}
|
||||||
Commands list: {{ commands }}
|
Commands list: {{ commands }}
|
||||||
Answers list: {{ answers }}
|
Answers list: {{ answers }}
|
||||||
|
Allowed chat IDs: {{ allowed_chat_ids if allowed_chat_ids | length > 0 else '(all)' }}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Execute Command Callback
|
# Execute Command Callback
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"version": "1.29.0"
|
"version": "1.30.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user