New setting to configure webhook/polling mode

pull/204/head
J-Rios 2024-05-18 13:07:39 +02:00
rodzic 01598855c5
commit c2aecf626e
Nie znaleziono w bazie danych klucza dla tego podpisu
4 zmienionych plików z 33 dodań i 14 usunięć

Wyświetl plik

@ -141,7 +141,7 @@ You can set Bot to be Private in "settings.py" file:
## Scalability (Polling or Webhook)
By default, Bot checks and receives updates from Telegram Servers by **Polling** (it requests and gets if there is any new updates in the Bot account corresponding to that Bot Token), this is really simple and can be used for low to median scale Bots. However, you can configure the Bot to use a **Webhook** instead if you expect to handle a large number of users/groups.
By default, Bot checks and receives updates from Telegram Servers by **Polling** (it periodically requests and gets from Telegram Server if there is any new updates in the Bot account corresponding to that Bot Token), this is really simple and can be used for low to median scale Bots. However, you can configure the Bot to use **Webhook** instead if you expect to handle a large number of users/groups (with webhook, the Telegram Server is the one that will connect to you machine and send updates to the Bot when there is any new update).
To use Webhook instead Polling, you need a signed certificate file in the system, you can create the key file and self-sign the cert through openssl tool:
@ -159,16 +159,22 @@ Once you have the key and cert files, setup the next lines in "settings.py" file
"WEBHOOK_CERT_PRIV_KEY" : SCRIPT_PATH + "/private.key",
```
In case you want to use a reverse proxy between Telegram Server and the system that runs the Bot, you need to setup the Proxy Webhook URL setting:
(Optional) In case you want to use a reverse proxy between Telegram Server and the system that runs the Bot, you need to setup the Proxy Webhook URL setting:
```python
"WEBHOOK_URL": "https://example.com:8443/TLG_JoinCaptchaBot"
```
To go back and use Polling instead Webhook, just set host address back to none:
Then, you need to change Bot connection mode from polling to webhook by setting to True the next configuration:
```python
"WEBHOOK_IP": "None",
"CAPTCHABOT_USE_WEBHOOK": True,
```
To go back and use Polling instead Webhook, just set the config back to False:
```python
"CAPTCHABOT_USE_WEBHOOK": False,
```
## Environment Variables Setup

Wyświetl plik

@ -48,6 +48,11 @@ CONST = {
"BOT_OWNER":
os_getenv("CAPTCHABOT_OWNER", SETTINGS["CAPTCHABOT_OWNER"]),
# Bot connection mode (webhook or polling)
"USE_WEBHOOK":
bool(int(os_getenv("CAPTCHABOT_USE_WEBHOOK",
SETTINGS["CAPTCHABOT_USE_WEBHOOK"]))),
# Bot Webhook Listen Address
"WEBHOOK_IP":
os_getenv("CAPTCHABOT_WEBHOOK_IP",

Wyświetl plik

@ -3900,7 +3900,7 @@ def tlg_app_run(app: Application) -> None:
function will be called at the end.
'''
logger.info("Bot Application Started")
if CONST["WEBHOOK_IP"] == "None":
if not CONST["USE_WEBHOOK"]:
logger.info("Setup Bot for Polling.")
app.run_polling(
drop_pending_updates=True,

Wyświetl plik

@ -41,33 +41,41 @@ SETTINGS = {
# Bot Owner (i.e. "@JoseTLG" or "123456789")
"CAPTCHABOT_OWNER": "XXXXXXXXX",
# Bot Webhook Listen address (keep in "None" for Polling or set to a
# valid address for Webhook)
# Enable Bot Webhook connection (False - Polling; True - Webhook)
# Set to True, to configure Bot for webhook connection mode
"CAPTCHABOT_USE_WEBHOOK": False,
# Bot Webhook Listen address
# Note: only used if CAPTCHABOT_USE_WEBHOOK is True
"CAPTCHABOT_WEBHOOK_IP": "0.0.0.0",
# Bot Webhook Listen Port (this is not used if WEBHOOK_URL is None)
# Bot Webhook Listen Port
# For Heroku, use the following: os_environ.get("PORT", "80")
# Note: only used if CAPTCHABOT_USE_WEBHOOK is True
"CAPTCHABOT_WEBHOOK_PORT": 8443,
# Bot Webhook URL
# This is the address that the Telegram server should use in case a
# reverse proxy is used between Telegram and the Bot.
# If you are using a reverse proxy, set this configuration.
"CAPTCHABOT_WEBHOOK_URL": "None",
# Note: only used if CAPTCHABOT_USE_WEBHOOK is True
"CAPTCHABOT_WEBHOOK_URL": None,
# Bot Webhook Path (this is not used if WEBHOOK_URL is None)
# Bot Webhook Path
# Note: only used if CAPTCHABOT_USE_WEBHOOK is True
"CAPTCHABOT_WEBHOOK_PATH": "/TLG_JoinCaptchaBot",
# Bot Webhook Certificate file path (this is not used if
# WEBHOOK_URL is None)
# Bot Webhook Certificate file path
# Note: only used if CAPTCHABOT_USE_WEBHOOK is True
"CAPTCHABOT_WEBHOOK_CERT": SCRIPT_PATH + "/cert.pem",
# Bot Webhook Certificate private key file path (this is not used
# if WEBHOOK_URL is None)
# Bot Webhook Certificate private key file path
# Note: only used if CAPTCHABOT_USE_WEBHOOK is True
"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)
# Note: only used if CAPTCHABOT_USE_WEBHOOK is True
"CAPTCHABOT_WEBHOOK_SECRET_TOKEN": None,
# Chats directory path