diff --git a/env.sample.php b/env.sample.php index 12eef22..141c8c6 100755 --- a/env.sample.php +++ b/env.sample.php @@ -5,3 +5,4 @@ $bot_api_key = '1234567890:Telegram_bot_api_key'; $bot_username = 'telegram_bot_username'; $hook_url = 'https://my.server.com/path/to/hook.php'; +$allowed_chat_ids = [123, 456]; // Set to empty array to allow message from any chat diff --git a/src/Commands/GenericmessageCommand.php b/src/Commands/GenericmessageCommand.php index 64a20b4..c7aa363 100755 --- a/src/Commands/GenericmessageCommand.php +++ b/src/Commands/GenericmessageCommand.php @@ -17,7 +17,16 @@ class GenericmessageCommand extends SystemCommand public function execute(): ServerResponse { + global $allowed_chat_ids; + $message = $this->getMessage(); + $chat_id = $message->getChat()->getId(); + if(count($allowed_chat_ids) > 0 && !in_array($chat_id, $allowed_chat_ids)) { + return Request::sendMessage([ + 'chat_id' => $chat_id, + 'text' => "Chat ID $chat_id not allowed", + ]); + } $text = $message->getText(true); if ($message->getMediaGroupId() || empty($text)) { @@ -33,7 +42,7 @@ class GenericmessageCommand extends SystemCommand $tail = $matches[3] ?? ''; return Request::sendMessage([ - 'chat_id' => $message->getChat()->getId(), + 'chat_id' => $chat_id, 'reply_to_message_id' => $message->getMessageId(), 'text' => "https://fxtwitter.com/$author/status/$tweetId$tail", 'disable_notification' => true,