The problem was the Content-Encoding
header, or rather, the compression method. The server automatically compressed the response using the Brotli algorithm and returned the Content-Encoding: br
header.
I came to the conclusion that the Telegram server is waiting for a response with gzip compression. I did not have the opportunity to configure the compression algorithm on the server, so I had to compress the response manually:
function compress($data) {
$supportsGzip = strpos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) !== false;
if ( $supportsGzip ) {
$content = gzencode( trim( preg_replace( '/\s+/', ' ', $data ) ), 9);
header('Content-Encoding: gzip');
} else {
$content = $data;
}
$offset = 60 * 60;
$expire = "expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header("content-type: text/html; charset: UTF-8");
header("cache-control: must-revalidate");
header( $expire );
header( 'Content-Length: ' . strlen( $content ) );
header('Vary: Accept-Encoding');
echo $content;
}
compress(""); //Compress an empty answer in gzip
After this update, they began to come in a single copy.
P.S. This refers to the text/html
format. If a webhook should return application/json
, then everything works without compression.