kopia lustrzana https://github.com/J-Rios/TLG_JoinCaptchaBot
Fixed webhook setup for work with revers proxy (#197)
* Fixed webhook setup for work with revers proxy * Added listening address setting for webhook. Corrected README.mdmaster
rodzic
01269fdb3e
commit
6ff4b4342a
|
@ -149,11 +149,13 @@ To use Webhook instead Polling, you need a signed certificate file in the system
|
|||
openssl req -newkey rsa:2048 -sha256 -nodes -keyout private.key -x509 -days 3650 -out cert.pem
|
||||
```
|
||||
|
||||
Once you have the key and cert files, setup the next lines in "settings.py" file to point to expected Webhook Host address, port and certificate file:
|
||||
Once you have the key and cert files, setup the next lines in "settings.py" file to point to expected Webhook URL, Host address, port, path and certificate file:
|
||||
|
||||
```python
|
||||
"WEBHOOK_HOST": "Current system IP/DNS here",
|
||||
"WEBHOOK_URL": "https://example.com:8443/TLG_JoinCaptchaBot"
|
||||
"WEBHOOK_IP": "0.0.0.0",
|
||||
"WEBHOOK_PORT": 8443,
|
||||
"WEBHOOK_PATH": "/TLG_JoinCaptchaBot"
|
||||
"WEBHOOK_CERT" : SCRIPT_PATH + "/cert.pem",
|
||||
"WEBHOOK_CERT_PRIV_KEY" : SCRIPT_PATH + "/private.key",
|
||||
```
|
||||
|
@ -161,7 +163,7 @@ Once you have the key and cert files, setup the next lines in "settings.py" file
|
|||
To use Polling instead Webhook, just set host value back to none:
|
||||
|
||||
```python
|
||||
"WEBHOOK_HOST": "None",
|
||||
"WEBHOOK_URL": "None",
|
||||
```
|
||||
|
||||
## Environment Variables Setup
|
||||
|
|
|
@ -48,25 +48,35 @@ CONST = {
|
|||
"BOT_OWNER":
|
||||
os_getenv("CAPTCHABOT_OWNER", SETTINGS["CAPTCHABOT_OWNER"]),
|
||||
|
||||
# Bot Webhook Host addres (keep in None for Polling or set to a
|
||||
# Bot Webhook URL (keep in None for Polling or set to a
|
||||
# valid address for Webhook)
|
||||
"WEBHOOK_HOST":
|
||||
os_getenv("CAPTCHABOT_WEBHOOK_HOST",
|
||||
SETTINGS["CAPTCHABOT_WEBHOOK_HOST"]),
|
||||
"WEBHOOK_URL":
|
||||
os_getenv("CAPTCHABOT_WEBHOOK_URL",
|
||||
SETTINGS["CAPTCHABOT_WEBHOOK_URL"]),
|
||||
|
||||
# Bot Webhook Host Port (this is not used if WEBHOOK_HOST is None)
|
||||
# Bot Webhook Listen Address (this is not used if WEBHOOK_URL is None)
|
||||
"WEBHOOK_IP":
|
||||
os_getenv("CAPTCHABOT_WEBHOOK_IP",
|
||||
SETTINGS["CAPTCHABOT_WEBHOOK_IP"]),
|
||||
|
||||
# Bot Webhook Listen Port (this is not used if WEBHOOK_URL is None)
|
||||
"WEBHOOK_PORT":
|
||||
int(os_getenv("CAPTCHABOT_WEBHOOK_PORT",
|
||||
SETTINGS["CAPTCHABOT_WEBHOOK_PORT"])),
|
||||
|
||||
# Bot Webhook path (this is not used if WEBHOOK_URL is None)
|
||||
"WEBHOOK_PATH":
|
||||
os_getenv("CAPTCHABOT_WEBHOOK_PATH",
|
||||
SETTINGS["CAPTCHABOT_WEBHOOK_PATH"]),
|
||||
|
||||
# Bot Webhook Certificate file path (this is not used if
|
||||
# WEBHOOK_HOST is None)
|
||||
# WEBHOOK_URL is None)
|
||||
"WEBHOOK_CERT":
|
||||
os_getenv("CAPTCHABOT_WEBHOOK_CERT",
|
||||
SETTINGS["CAPTCHABOT_WEBHOOK_CERT"]),
|
||||
|
||||
# Bot Webhook Certificate private key file path (this is not used
|
||||
# if WEBHOOK_HOST is None)
|
||||
# if WEBHOOK_URL is None)
|
||||
"WEBHOOK_CERT_PRIV_KEY":
|
||||
os_getenv("CAPTCHABOT_WEBHOOK_CERT_PRIV_KEY",
|
||||
SETTINGS["CAPTCHABOT_WEBHOOK_CERT_PRIV_KEY"]),
|
||||
|
|
|
@ -3896,7 +3896,7 @@ def tlg_app_run(app: Application) -> None:
|
|||
function will be called at the end.
|
||||
'''
|
||||
logger.info("Bot Application Started")
|
||||
if CONST["WEBHOOK_HOST"] == "None":
|
||||
if CONST["WEBHOOK_URL"] == "None":
|
||||
logger.info("Setup Bot for Polling.")
|
||||
app.run_polling(
|
||||
drop_pending_updates=True,
|
||||
|
@ -3905,14 +3905,13 @@ def tlg_app_run(app: Application) -> None:
|
|||
else:
|
||||
logger.info("Setup Bot for Webhook.")
|
||||
app.run_webhook(
|
||||
webhook_url=f'https://{CONST["WEBHOOK_HOST"]}:'
|
||||
f'{CONST["WEBHOOK_PORT"]}/{CONST["TOKEN"]}',
|
||||
url_path=CONST["TOKEN"],
|
||||
webhook_url=CONST["WEBHOOK_URL"],
|
||||
listen=CONST["WEBHOOK_IP"],
|
||||
port=CONST["WEBHOOK_PORT"],
|
||||
key=CONST["WEBHOOK_CERT_PRIV_KEY"],
|
||||
url_path=CONST["WEBHOOK_PATH"],
|
||||
cert=CONST["WEBHOOK_CERT"],
|
||||
key=CONST["WEBHOOK_CERT_PRIV_KEY"],
|
||||
secret_token=CONST["WEBHOOK_SECRET_TOKEN"],
|
||||
listen="0.0.0.0",
|
||||
drop_pending_updates=True,
|
||||
allowed_updates=Update.ALL_TYPES
|
||||
)
|
||||
|
|
|
@ -41,20 +41,30 @@ SETTINGS = {
|
|||
# Bot Owner (i.e. "@JoseTLG" or "123456789")
|
||||
"CAPTCHABOT_OWNER": "XXXXXXXXX",
|
||||
|
||||
# Bot Webhook Host address (keep in "None" for Polling or set to a
|
||||
# Bot Webhook URL (keep in "None" for Polling or set to a
|
||||
# valid address for Webhook)
|
||||
"CAPTCHABOT_WEBHOOK_HOST": "None",
|
||||
# This is the address that the Telegram server should call.
|
||||
# If you are not using a reverse proxy, then the WEBHOOK_URL
|
||||
# should look something like this:
|
||||
# https://example.com:{WEBHOOK_PORT}/{WEBHOOK_PATH}
|
||||
"CAPTCHABOT_WEBHOOK_URL": "None",
|
||||
|
||||
# Bot Webhook Host Port (this is not used if WEBHOOK_HOST is None)
|
||||
# Bot Webhook Listen address (this is not used if WEBHOOK_URL is None)
|
||||
"CAPTCHABOT_WEBHOOK_IP": "0.0.0.0",
|
||||
|
||||
# Bot Webhook Listen Port (this is not used if WEBHOOK_URL is None)
|
||||
# For Heroku, use the following: os_environ.get("PORT", "80")
|
||||
"CAPTCHABOT_WEBHOOK_PORT": 8443,
|
||||
|
||||
# Bot Webhook Path (this is not used if WEBHOOK_URL is None)
|
||||
"CAPTCHABOT_WEBHOOK_PATH": "/TLG_JoinCaptchaBot",
|
||||
|
||||
# Bot Webhook Certificate file path (this is not used if
|
||||
# WEBHOOK_HOST is None)
|
||||
# WEBHOOK_URL is None)
|
||||
"CAPTCHABOT_WEBHOOK_CERT": SCRIPT_PATH + "/cert.pem",
|
||||
|
||||
# Bot Webhook Certificate private key file path (this is not used
|
||||
# if WEBHOOK_HOST is None)
|
||||
# if WEBHOOK_URL is None)
|
||||
"CAPTCHABOT_WEBHOOK_CERT_PRIV_KEY": SCRIPT_PATH + "/private.key",
|
||||
|
||||
# Bot Webhook Secret Token to verify request from Telegram Server
|
||||
|
|
Ładowanie…
Reference in New Issue