Hey everyone! I’m having some trouble with my Telegram bot. I set up a Tornado HTTP server with SSL and configured a webhook for my bot. But for some reason, the server isn’t receiving any POST requests from Telegram.
Here’s a simplified version of my code:
import tornado.web
import tornado.httpserver
import tornado.ioloop
class BotHandler(tornado.web.RequestHandler):
def post(self):
print('Webhook triggered')
def get(self):
print('Test GET request')
self.write('Bot server is running')
app = tornado.web.Application([(r'/', BotHandler)])
if __name__ == '__main__':
server = tornado.httpserver.HTTPServer(app, ssl_options={
'certfile': 'cert.pem',
'keyfile': 'key.pem'
})
server.listen(8443)
tornado.ioloop.IOLoop.current().start()
I’m pretty sure the SSL setup is correct, but the POST requests aren’t coming through. Any ideas what might be causing this? Thanks in advance for your help!
hey emma, i had similar issues. make sure ur webhook URL matches exactly what u set in telegram’s api. also, double-check ur SSL cert is valid and not expired. sometimes firewalls can block incoming posts too. if none of that works, try printing out the full request data in ur post method to see if anythings coming thru at all
As someone who’s wrestled with Telegram bots before, I can relate to your frustration. One thing that’s not immediately obvious from your code is whether you’ve actually set the webhook with Telegram’s API. You need to make a separate request to https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook with your server’s URL.
Also, Telegram is pretty strict about ports. They only allow 443, 80, 88, or 8443 for webhooks. Since you’re using 8443, that should be fine, but make sure your server is actually accessible from the internet on that port.
If you’ve done all that and it’s still not working, try adding some logging to your post method to see if it’s being called at all. Sometimes the requests come through but fail silently. Something like:
def post(self):
print(‘Webhook triggered’)
print(self.request.body)
# process the update here
This way, you’ll see if Telegram is hitting your endpoint at all, and what data it’s sending if it is.
I encountered a similar issue when setting up my Telegram bot. One thing that helped me was enabling debug logging in Tornado to get more visibility into incoming requests. You can do this by adding:
import logging
logging.getLogger(‘tornado.access’).setLevel(logging.DEBUG)
Also, ensure you’ve properly set the webhook URL with Telegram’s setWebhook method. The URL should be the full HTTPS path to your server endpoint.
If you’re still not seeing requests, try temporarily disabling SSL and testing with a plain HTTP server on a different port. This can help isolate whether it’s an SSL issue or something else. Just remember to switch back to HTTPS for production use.