Report this

What is the reason for this report?

Telegram Bot with WebHook Fails

Posted on April 1, 2020

I intend to set up my Telegram bot with webhook. I have configured everything according to instructions I have found from valid sources.

However, Bot is not receiving webhook updates and I get below error when I send “getWebhookInfo” request to Telegram API.

{"ok":true,"result":{"url":"https://161.35.18.8/1058222550:AAFPb5oCPKfKLkJbMlvzg1rKEDw7-qx30Ww","has_custom_certificate":true,"pending_update_count":4,"last_error_date":1585773597,"last_error_message":"Connection timed out","max_connections":40}}

Here is the configuration I have done for the droplet on Digitalocean.

  • Created a self-signed key and certificate pair with OpenSSL and put them in /etc/ssl/private/ and /etc/ssl/certs/

  • The firewall was adjusted and below is the FW status:

To                         Action      From
--                         ------      ----
Nginx HTTP                 ALLOW       Anywhere
22/tcp                     ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
Nginx HTTP (v6)            ALLOW       Anywhere (v6)
22/tcp (v6)                ALLOW       Anywhere (v6)
OpenSSH (v6)               ALLOW       Anywhere (v6)
server {
    listen              443 ssl;
    server_name         SERVER_IP_ADDRESS;
    ssl_certificate     bot.pem;
    ssl_certificate_key private.key;

    location /TOKEN1 {
        proxy_pass http://127.0.0.1:5000/TOKEN1/;
    }

    location /TOKEN2 {
        proxy_pass http://127.0.0.1:5001/TOKEN2/;
    }
}
  • Tested Nginx configurations and restart the webserver by executing sudo nginx -t && sudo systemctl restart nginx and getting the below output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

In my application file which is running on the server, the python script is as follows to get updates from Telegram :

updater.start_webhook(listen='127.0.0.1', port=5000, url_path='TokenID')
updater.bot.set_webhook(webhook_url='https://<DropletID>/TokenId',
                        certificate=open('bot.pem', 'rb'))

Am I missing something somewhere? Any idea what could be the cause of the problem? Any help is very much appreciated. Thanks.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.