R
R
Roman2020-02-28 19:01:19
PHP
Roman, 2020-02-28 19:01:19

Telegram bot webhook not working?

Good afternoon everyone!

I am writing a chat bot, I added a webhook (the handler is on a European shared hosting).

I send a request via Postman, everything works, I write a message to the bot in telegram - silence.

Called getWebhookInfo, got the following:

Array
(
    [ok] => 1
    [result] => Array
        (
            [url] => https://webhook.url.php
            [has_custom_certificate] => 
            [pending_update_count] => 6
            [last_error_date] => 1582905610
            [last_error_message] => Bad Request: zlib error -5
            [max_connections] => 40
        )
)


Has anyone encountered a similar problem?
How did you decide?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
elena81kachanova, 2020-02-28
@elena81kachanova

How do you handle the response from Telegram?

K
KandiDev, 2020-03-24
@KandiDev

The problem is the compression type of your server's response. Most likely your server returns:
Content-Encoding: br
The Telegram server cannot parse the response using gzip, eventually returning an error related to zlib.
Solution: change the compression type of your server to gzip or use PHP code for compression:

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(""); //Сжимаем пустой ответ в gzip

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question