我制作了一個電報機器人,它在我們的電報聊天中記錄嚴重錯誤。該機器人已在另一個 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(); }}提前致謝
3 回答

慕尼黑8549860
TA貢獻1818條經驗 獲得超11個贊
問題很可能是您的消息中的一個變量($user、$path、$file、$line)的內容,它創建了一個無效的 markdown 字符串。也許您有一個開盤降價符號,但沒有相應的收盤符號。喜歡*
或_
。
如果這沒有幫助,請在此處發布準確的消息,替換變量,以便我們發現降價錯誤。

胡說叔叔
TA貢獻1804條經驗 獲得超8個贊
如果您只想發送純文本而不需要 Markdown 或 HTML,只需parse_mode
完全刪除該參數即可。它將以純文本形式發送消息,您不必擔心任何特殊字符(除了對消息文本進行編碼的 URL)。
- 3 回答
- 0 關注
- 254 瀏覽
添加回答
舉報
0/150
提交
取消