3

I developed a Telegram bot with the python-telegram-bot library and now i want to deploy it in my server, so i setup a webhook(following the Official Wiki) but when i try to communicate with my bot i don't get any reply.

This is the source of the bot:

def main():
   PRIVTOKEN = "1134xxxx"
   updater = Updater(PRIVTOKEN)

   dp = updater.dispatcher

   dp.add_handler(CommandHandler("start", start))
   # ...

   updater.start_webhook(listen='127.0.0.1',
                         port=8843,
                         url_path=PRIVTOKEN)
   updater.bot.set_webhook(webhook_url='https://example.com/' + PRIVTOKEN,
                           certificate=open("cert.pem", "rb"))
   print("bot started")
   updater.idle()

the nginx config file:

server {
  listen 443 ssl;
  server_name example.com;


  location /1134xxxx {
     proxy_pass http://127.0.0.1:8443;
  }
}

The netstat status:

sudo netstat -an | grep 8843
tcp        0      127.0.0.1:8843            0.0.0.0:*               LISTEN 

No other errors where logged either by the bot(i've enabled the error logs) or by nginx(access/error.log)

I’ve also added a custom rule for 8843 port in the firewall.

beep
  • 1,057
  • 2
  • 11
  • 23
  • 1
    Please re-check your description - your python app listens on 8843, but nginx proxies to port 8443 (netstat sucks, I recommend to use lsof -i :8443) – Alex C Jun 21 '18 at 07:18
  • it doesn't work either by fixing this typo error – beep Jun 21 '18 at 08:47
  • I didn't say it will help, I just wanted to understand situation clearly. Please update initial description. Then I suggest to check hop by hop: make sure your packets can reach Nginx and then make sure packets from Nginx can reach your app. You can do it using tcpdump for example or using some kind of logging(including nginx logs) – Alex C Jun 22 '18 at 08:41
  • try add a letsencrypt free https certificate to your server – teleme.io Jul 01 '18 at 16:09

1 Answers1

1

Telegram supports only https requests. note this.

my nginx config:

server {
        listen 80;
        listen 443 ssl;
        server_name example.com www.example.com;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
        if ($scheme = http) {
            return 301 https://$server_name$request_uri;
        }
    location / {
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://localhost:5005/;
    }
}
dzNET
  • 930
  • 1
  • 9
  • 14