首页 > 解决方案 > 电报机器人找不到从(截断...)开始的实体的结尾

问题描述

我制作了一个电报机器人,它在我们的电报聊天中记录严重错误。这个机器人已经在另一个 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更改MarkdownHTML解决了该问题,但我正在尝试解决为什么会这样。

这是我要发送的字符串:

$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();
    }
}

提前致谢

标签: phpsymfonytelegram-bot

解决方案


问题很可能是消息中的一个变量($user、$path、$file、$line)的内容,这会创建一个无效的降价字符串。也许您有一个开场降价符号而没有相应的闭幕符号。喜欢*_

如果这没有帮助,请在此处发布确切的消息,并替换变量,以便我们发现降价错误。


推荐阅读