我制作了一个电报机器人,它在我们的电报聊天中记录严重错误。该机器人已在另一个 symfony 应用程序 (4.4) 中使用,并且运行良好。
但是现在我试图在 Symfony 3.4 项目中使用它,并且在生成错误时,电报响应:
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...)
但是,将parse_modefrom更改为Markdown可以HTML解决问题,但我正在努力思考为什么会这样。
这是我要发送的字符串:
$message = "$user just had an error at: $path\n`$error`\n$file:$line";
这是发送请求的函数:
/**
* @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();
}
}
提前致谢
慕尼黑8549860
侃侃无极
胡说叔叔