Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/Monolog/Handler/TelegramBotHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Copy Markdown

@daniser daniser Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be changed to:

$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,
Expand Down