Question
Telegram Bot with WebHook Fails
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)
- Next, Nginx was configured following instructions given in [https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks](http://) and the
default
server block file in the /etc/nginx/sites-available directory was modified as follows:
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.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×