php - 电报机器人找不到从(截断...)开始的实体的结尾
问题描述
我制作了一个电报机器人,它在我们的电报聊天中记录严重错误。这个机器人已经在另一个 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_mode
from更改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();
}
}
提前致谢
解决方案
问题很可能是消息中的一个变量($user、$path、$file、$line)的内容,这会创建一个无效的降价字符串。也许您有一个开场降价符号而没有相应的闭幕符号。喜欢*
或_
。
如果这没有帮助,请在此处发布确切的消息,并替换变量,以便我们发现降价错误。
推荐阅读
- bash - 如何检查 docker Cassandra 实例是否已准备好连接
- angular - Angular 原理图可以读取主目录之外的文件吗?
- java - 将字符串划分为 ArrayList
- powershell - 使用设备门户 API 将应用程序安装到 Hololens 的 PS 脚本出错
- php - 在php中添加具有动态下拉列表的动态行jquery
- javascript - 我可以使用签名的 url 上传到 Spaces 吗?
- flutter - 如何防止使用“无限”项重建多个条子列表?
- javascript - 不同的登录名,但在两台计算机上共享实时会话,我使用什么平台以及如何构建它?
- c++ - OpenGL相机在第一次鼠标输入时突然跳跃?
- django - 如何在 Django 2 中将多个模型加载到单个模板