I've made a telegram bot which logs critical errors in our telegram chat. This bot has been used in another symfony application (4.4), and worked fine.
But now I'm trying to use it in a Symfony 3.4 project and upon generating an error, telegram responds with:
resulted in a `400 Bad Request` response:
{"ok":false,"error_code":400,"description":"Bad Request: can't parse entities: Can't find end of the entity starting at (truncated...)
However, changing the parse_mode
from Markdown
to HTML
fixes the issue, but I'm trying to wrap my head around it why this could be.
This is the string I'm trying to send:
$message = "$user just had an error at: $path\n`$error`\n$file:$line";
This is the function which sends the request:
/**
* @param $method
* @param $headers
* @param $body
* @return mixed|ResponseInterface
* @throws GuzzleException
*/
public function APIMethod($method, $headers, $body)
{
$client = new Client();
$uri = 'https://api.telegram.org/bot' . $this->telegramToken . '/' . $method;
return $client->request('POST', $uri, [
'headers' => $headers,
'form_params' => $body,
]);
}
/**
* @param $telegramId
* @param $text
* @return mixed|ResponseInterface
* @throws GuzzleException
*/
public function sendNotification($telegramId, $text)
{
try {
return $this->APImethod('sendMessage', [
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept' => 'application/json',
], [
'chat_id' => $telegramId,
'parse_mode' => 'Markdown',
'text' => $text,
'disable_web_page_preview' => true,
]);
} catch (Exception $exception) {
return $exception->getMessage();
}
}
Thanks in advance