diff --git a/app/Services/TelegramService.php b/app/Services/TelegramService.php index ffd9797..83f52c7 100644 --- a/app/Services/TelegramService.php +++ b/app/Services/TelegramService.php @@ -29,9 +29,7 @@ class TelegramService public function sendMessage(int $chatId, string $text, string $parseMode = ''): void { - if ($parseMode === 'markdown') { - $text = $this->escapeMarkdown($text); - } + $text = $parseMode === 'markdown' ? str_replace('_', '\_', $text) : $text; $this->request('sendMessage', [ 'chat_id' => $chatId, @@ -40,26 +38,6 @@ class TelegramService ]); } - /** - * 转义 Telegram Markdown 特殊字符 - */ - protected function escapeMarkdown(string $text): string - { - $escapeChars = ['_', '*', '`', '[']; - $escapedText = ''; - - for ($i = 0; $i < strlen($text); $i++) { - $char = $text[$i]; - if (in_array($char, $escapeChars, true)) { - $escapedText .= '\\' . $char; - } else { - $escapedText .= $char; - } - } - - return $escapedText; - } - public function approveChatJoinRequest(int $chatId, int $userId): void { $this->request('approveChatJoinRequest', [