6

I just find the post without any reply on stackoverflow when i create this post... TelegramBot. "Webhook can be set up only on ports 80, 88, 443 or 8443" error on heroku webserver

my testing code is here:

from configparser import ConfigParser
import logging

import os
    
import telegram
from flask import Flask, request
from telegram.ext import  Updater, Dispatcher, MessageHandler, Filters, CommandHandler

env = ConfigParser()
env.read('config.ini')
TOKEN = env['TELEGRAM']['ACCESS_TOKEN']

PORT = int(os.environ.get('PORT', '8443'))

updater = Updater(token=TOKEN)


#
#body part ( that's not important to show)
#


updater.start_webhook(listen="0.0.0.0",
                      port=PORT,
                      url_path=TOKEN)
updater.bot.set_webhook("https://tgbot00.herokuapp.com/" + TOKEN)
updater.idle()

but server told me ...

here2021-03-19T14:48:06.712894+00:00 app[web.1]: Error while bootstrap set webhook: Bad webhook: webhook can be set up only on ports 80, 88, 443 or 8443

2021-03-19T14:48:06.713033+00:00 app[web.1]: Failed bootstrap phase after 0 retries (Bad webhook: webhook can be set up only on ports 80, 88, 443 or 8443)

I have struggled these about a week and almost success but somehow so less information found on google

Do I need to setup something on my remoted Linux system about PORT.?

could someone help .?

thx a lot...!

UPDATE---------------------------------------- https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks#heroku

I think this is not about SSL problem

Heroku
On Heroku using webhook can be beneficial on the free-plan because it will
automatically manage the downtime required. The reverse proxy is set up for you and an environment 
is created. From this environment you will have to extract the port the bot is supposed to listen on. 
Heroku manages the SSL on the proxy side, so you don't have provide the certificate yourself.
codinLover
  • 73
  • 2
  • 7
  • Looks all fine, how did you define the webhook url? Maybe check that the URL starts with HTTPS – Beppe C Mar 19 '21 at 16:42
  • um... i am sorry , what do you mean of "the webhook url" ..? btw . thank you so much your attention – codinLover Mar 19 '21 at 16:56
  • yes, you call the Telegram setWebook URL to define the url of your service – Beppe C Mar 19 '21 at 17:19
  • ops you mean api.telegram.org/bot{}/setWebhook?url={} ..... i just set url to "https://{appname}.herokuapp.com/" that shows on heroku setting - domain – codinLover Mar 19 '21 at 17:33
  • it looks all good, really weird. It seems that your Heroku app doesnt run on SSL which should not be the case as (like you pointed out) the SSL is provided by the platform and you dont need to do anything – Beppe C Mar 19 '21 at 20:22
  • Something to try is to print out the value of PORT, to make sure it does get the value provided by Heroku – Beppe C Mar 19 '21 at 20:25
  • So , i do as you told.. There is no any number show is 80, 88, 443 or 8443 So.., what's the next step..? – codinLover Mar 20 '21 at 05:28
  • Have no idea the next step i should do . Is there more information complete detail information online .? – codinLover Mar 20 '21 at 05:28
  • btw thanks your advice even this is not a big helpful... lol – codinLover Mar 20 '21 at 05:39
  • Try to get the PORT from within the method that call bot.setWebhook. Everything else looks like my repo where I deploy to Heroku without problems, feel free to have a look https://github.com/gcatanese/TelegramBotDemo – Beppe C Mar 20 '21 at 14:13
  • I just try using polling without using < Flask> with another code to test ....just Updater(token= {}) and it all works smooth.... I just have a look of your link example . its pretty cool !! thx a lot = D – codinLover Mar 21 '21 at 01:32

1 Answers1

11

Documentation updated: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks#heroku

import os
TOKEN = "TOKEN"
PORT = int(os.environ.get('PORT', '8443'))
updater = Updater(TOKEN)
# add handlers
updater.start_webhook(listen="0.0.0.0",
                      port=PORT,
                      url_path=TOKEN,
                      webhook_url="https://<appname>.herokuapp.com/" + TOKEN)
updater.idle()

Not use set_webhook , use webhook_url param in start_webhook

Luis Ciber
  • 181
  • 6