Support webhook secret_token and os environment in settings file

pull/195/head
J-Rios 2023-03-12 01:17:58 +01:00
rodzic 47e597ef6f
commit cecd72b822
Nie znaleziono w bazie danych klucza dla tego podpisu
3 zmienionych plików z 20 dodań i 6 usunięć

Wyświetl plik

@ -67,6 +67,12 @@ CONST = {
os_getenv("CAPTCHABOT_WEBHOOK_CERT_PRIV_KEY", \
SETTINGS["CAPTCHABOT_WEBHOOK_CERT_PRIV_KEY"]),
# Bot Webhook Secret Token to verify request from Telegram Server
# (don't use the Bot Token, for security reason it must be other)
"WEBHOOK_SECRET_TOKEN": \
os_getenv("CAPTCHABOT_WEBHOOK_SECRET_TOKEN", \
SETTINGS["CAPTCHABOT_WEBHOOK_SECRET_TOKEN"]),
# Chats directory path
"CHATS_DIR": \
os_getenv("CAPTCHABOT_CHATS_DIR", SETTINGS["CAPTCHABOT_CHATS_DIR"]),

Wyświetl plik

@ -3758,11 +3758,13 @@ def tlg_app_run(app: Application) -> None:
else:
logger.info("Setup Bot for Webhook.")
app.run_webhook(
drop_pending_updates=True, listen="0.0.0.0",
port=CONST["WEBHOOK_PORT"], url_path=CONST["TOKEN"],
key=CONST["WEBHOOK_CERT_PRIV_KEY"], cert=CONST["WEBHOOK_CERT"],
webhook_url=f'https://{CONST["WEBHOOK_HOST"]}:'
f'{CONST["WEBHOOK_PORT"]}/{CONST["TOKEN"]}',
webhook_url=CONST["WEBHOOK_HOST"],
port=CONST["WEBHOOK_PORT"],
key=CONST["WEBHOOK_CERT_PRIV_KEY"],
cert=CONST["WEBHOOK_CERT"],
secret_token=CONST["WEBHOOK_SECRET_TOKEN"],
listen="0.0.0.0",
drop_pending_updates=True,
allowed_updates=Update.ALL_TYPES
)
logger.info("Bot Application Finished")

Wyświetl plik

@ -20,6 +20,7 @@ Version:
###############################################################################
from os import path as os_path
from os import environ as os_environ
# Actual settings.py full path directory name
SCRIPT_PATH = os_path.dirname(os_path.realpath(__file__))
@ -40,11 +41,12 @@ SETTINGS = {
# Bot Owner (i.e. "@JoseTLG" or "123456789")
"CAPTCHABOT_OWNER": "XXXXXXXXX",
# Bot Webhook Host addres (keep in None for Polling or set to a
# Bot Webhook Host address (keep in "None" for Polling or set to a
# valid address for Webhook)
"CAPTCHABOT_WEBHOOK_HOST": "None",
# Bot Webhook Host Port (this is not used if WEBHOOK_HOST is None)
# For Heroku, use the following: os_environ.get("PORT", "80")
"CAPTCHABOT_WEBHOOK_PORT": 8443,
# Bot Webhook Certificate file path (this is not used if
@ -55,6 +57,10 @@ SETTINGS = {
# if WEBHOOK_HOST is None)
"CAPTCHABOT_WEBHOOK_CERT_PRIV_KEY" : SCRIPT_PATH + "/private.key",
# Bot Webhook Secret Token to verify request from Telegram Server
# (don't use the Bot Token, for security reason it must be other)
"CAPTCHABOT_WEBHOOK_SECRET_TOKEN" : None,
# Chats directory path
"CAPTCHABOT_CHATS_DIR": SCRIPT_PATH + "/data/chats",