Skip to content
Open
Changes from all commits
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
28 changes: 26 additions & 2 deletions 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';
$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