@@ -17,6 +17,15 @@ class DbConfig(NamedTuple):
1717 database : str
1818
1919
20+ class RedisConfig (NamedTuple ):
21+ """Redis database configuration"""
22+
23+ host : str
24+ port : int
25+ database_index : int
26+ password : str
27+
28+
2029class WebhookCredentials (NamedTuple ):
2130 """Represents credentials to use webhook"""
2231
@@ -39,12 +48,16 @@ class Config(NamedTuple):
3948
4049 tg_bot : TgBot
4150 db : DbConfig
51+ redis : RedisConfig | None
4252 webhook : WebhookCredentials | None
4353
4454
4555# Change USE_WEBHOOK to True to use a webhook instead of long polling
4656USE_WEBHOOK : bool = False
4757
58+ # Change USE_REDIS to True to use redis storage for FSM instead of memory
59+ USE_REDIS : bool = False
60+
4861_BASE_DIR : Path = Path (__file__ ).resolve ().parent .parent
4962LOCALES_DIR : str = normpath (join (_BASE_DIR , "tgbot/locales" ))
5063TEMP_DIR : str = normpath (join (_BASE_DIR , "tgbot/temp" ))
@@ -71,11 +84,25 @@ def load_config() -> Config:
7184 user = env .str ("POSTGRES_DB_USER" ),
7285 database = env .str ("POSTGRES_DB_NAME" ),
7386 ),
74- webhook = WebhookCredentials (
75- wh_host = env .str ("WEBHOOK_HOST" ),
76- wh_path = env .str ("WEBHOOK_PATH" ),
77- wh_token = env .str ("WEBHOOK_TOKEN" ),
78- app_host = env .str ("APP_HOST" ),
79- app_port = env .int ("APP_PORT" ),
80- ) if USE_WEBHOOK else None
87+ redis = (
88+ RedisConfig (
89+ host = env .str ("REDIS_HOST" ),
90+ port = env .int ("REDIS_PORT" ),
91+ database_index = env .int ("REDIS_DB_INDEX" ),
92+ password = env .str ("REDIS_DB_PASS" ),
93+ )
94+ if USE_REDIS
95+ else None
96+ ),
97+ webhook = (
98+ WebhookCredentials (
99+ wh_host = env .str ("WEBHOOK_HOST" ),
100+ wh_path = env .str ("WEBHOOK_PATH" ),
101+ wh_token = env .str ("WEBHOOK_TOKEN" ),
102+ app_host = env .str ("APP_HOST" ),
103+ app_port = env .int ("APP_PORT" ),
104+ )
105+ if USE_WEBHOOK
106+ else None
107+ ),
81108 )
0 commit comments