From 879b333a1197720412b97bce9823af32561d5163 Mon Sep 17 00:00:00 2001 From: latan Date: Thu, 10 Aug 2023 14:52:39 +0300 Subject: [PATCH] Add guidance comments on obtaining bot tokens from environment variables --- examples/echo_bot.py | 2 ++ examples/echo_bot_webhook.py | 3 +++ examples/echo_bot_webhook_ssl.py | 3 +++ examples/finite_state_machine.py | 7 ++++++- examples/multibot.py | 5 ++++- examples/specify_updates.py | 3 +++ examples/web_app/main.py | 7 +++++-- 7 files changed, 26 insertions(+), 4 deletions(-) diff --git a/examples/echo_bot.py b/examples/echo_bot.py index fab0fcf5..ac789ad6 100644 --- a/examples/echo_bot.py +++ b/examples/echo_bot.py @@ -10,6 +10,8 @@ from aiogram.utils.markdown import hbold # Bot token can be obtained via https://t.me/BotFather TOKEN = "42:TOKEN" +# However, is recommended to get the token from environment variable: +# TOKEN = getenv("BOT_TOKEN") # All handlers should be attached to the Router (or Dispatcher) router = Router() diff --git a/examples/echo_bot_webhook.py b/examples/echo_bot_webhook.py index cc11a9f7..b8632384 100644 --- a/examples/echo_bot_webhook.py +++ b/examples/echo_bot_webhook.py @@ -15,6 +15,9 @@ from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_applicati # Bot token can be obtained via https://t.me/BotFather TOKEN = "42:TOKEN" +# However, is recommended to get the token from environment variable: +# TOKEN = getenv("BOT_TOKEN") + # Webserver settings # bind localhost only to prevent any external access diff --git a/examples/echo_bot_webhook_ssl.py b/examples/echo_bot_webhook_ssl.py index c226dcae..83aff5c6 100644 --- a/examples/echo_bot_webhook_ssl.py +++ b/examples/echo_bot_webhook_ssl.py @@ -15,6 +15,9 @@ from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_applicati # Bot token can be obtained via https://t.me/BotFather TOKEN = "42:TOKEN" +# However, is recommended to get the token from environment variable: +# TOKEN = getenv("BOT_TOKEN") + # Webserver settings # bind localhost only to prevent any external access diff --git a/examples/finite_state_machine.py b/examples/finite_state_machine.py index b916efeb..1aaa59ab 100644 --- a/examples/finite_state_machine.py +++ b/examples/finite_state_machine.py @@ -16,6 +16,11 @@ from aiogram.types import ( ReplyKeyboardRemove, ) +TOKEN = "42:TOKEN" +# However, is recommended to get the token from environment variable: +# TOKEN = getenv("BOT_TOKEN") + + form_router = Router() @@ -122,7 +127,7 @@ async def show_summary(message: Message, data: Dict[str, Any], positive: bool = async def main(): - bot = Bot(token=getenv("TELEGRAM_TOKEN"), parse_mode=ParseMode.HTML) + bot = Bot(token=TOKEN, parse_mode=ParseMode.HTML) dp = Dispatcher() dp.include_router(form_router) diff --git a/examples/multibot.py b/examples/multibot.py index 70471ee4..9f9c0523 100644 --- a/examples/multibot.py +++ b/examples/multibot.py @@ -21,7 +21,10 @@ from aiogram.webhook.aiohttp_server import ( main_router = Router() BASE_URL = getenv("BASE_URL", "https://example.com") -MAIN_BOT_TOKEN = getenv("TELEGRAM_TOKEN") +MAIN_BOT_TOKEN = "42:TOKEN" +# However, is recommended to get the token from environment variable: +# MAIN_BOT_TOKEN = getenv("BOT_TOKEN") + WEB_SERVER_HOST = "127.0.0.1" WEB_SERVER_PORT = 8080 diff --git a/examples/specify_updates.py b/examples/specify_updates.py index 86f6651c..3f10f02a 100644 --- a/examples/specify_updates.py +++ b/examples/specify_updates.py @@ -15,6 +15,9 @@ from aiogram.types import ( from aiogram.utils.markdown import hbold, hcode TOKEN = "42:TOKEN" +# However, is recommended to get the token from environment variable: +# TOKEN = getenv("BOT_TOKEN") + logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) diff --git a/examples/web_app/main.py b/examples/web_app/main.py index 677b4076..96e1f5c1 100644 --- a/examples/web_app/main.py +++ b/examples/web_app/main.py @@ -11,7 +11,10 @@ from aiogram import Bot, Dispatcher from aiogram.types import MenuButtonWebApp, WebAppInfo from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_application -TELEGRAM_TOKEN = getenv("TELEGRAM_TOKEN") +TOKEN = "42:TOKEN" +# However, is recommended to get the token from environment variable: +# TOKEN = getenv("BOT_TOKEN") + APP_BASE_URL = getenv("APP_BASE_URL") @@ -23,7 +26,7 @@ async def on_startup(bot: Bot, base_url: str): def main(): - bot = Bot(token=TELEGRAM_TOKEN, parse_mode="HTML") + bot = Bot(token=TOKEN, parse_mode="HTML") dispatcher = Dispatcher() dispatcher["base_url"] = APP_BASE_URL dispatcher.startup.register(on_startup)