diff --git a/src/Monolog/Handler/TelegramBotHandler.php b/src/Monolog/Handler/TelegramBotHandler.php index e6b23bc48..b91c6cf4f 100644 --- a/src/Monolog/Handler/TelegramBotHandler.php +++ b/src/Monolog/Handler/TelegramBotHandler.php @@ -251,17 +251,41 @@ protected function send(string $message): void } } + /** + * Returns the Telegram Bot API base URL. + * Override in a subclass to point to a self-hosted Bot API server. + */ + protected function botApiUrl(): string + { + return self::BOT_API; + } + + /** + * Returns extra HTTP headers to send with every Telegram API request. + * Override in a subclass to inject custom headers (e.g. auth tokens, tracing). + * + * @return string[] + */ + protected function getCurlHeaders(): array + { + return []; + } + protected function sendCurl(string $message): void { if ('' === trim($message)) { return; } - + $ch = curl_init(); - $url = self::BOT_API . $this->apiKey . '/SendMessage'; + $url = $this->botApiUrl() . $this->apiKey . '/SendMessage'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + $headers = $this->getCurlHeaders(); + if ($headers !== []) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } $params = [ 'text' => $message, 'chat_id' => $this->channel,