Skip to content

Commit

Permalink
Implement webhook (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobaUbisoft17 authored May 10, 2024
1 parent 250782d commit 5608742
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from app.bot.handlers import Logic
from app.bot.polling import Polling
from app.bot.task import MailingTask
from app.bot.webhook import Webhook
from app.db import AiosqliteConnection, Subscribers, create_db
from app.logger import logger
from app.weather import OwmWeather
Expand All @@ -34,4 +35,11 @@ async def main():
if config.RUN_TYPE == "polling":
await Polling(dp, tasks=[task]).run(bot)
elif config.RUN_TYPE == "webhook":
...
await Webhook(
dp,
[task],
config.WEBHOOK_URL,
config.WEBHOOK_PATH,
config.WEBHOOK_HOST,
config.WEBHOOK_PORT,
).run(bot)
2 changes: 1 addition & 1 deletion app/bot/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run(self, bot):
def on_startup(bot, webhook_url, tasks):
async def on_startup():
"""Функция перед запуском бота в режиме webhook"""
await bot.set_webhook(webhook_url, drop_pending_updates=True)
await bot.set_webhook(webhook_url)
for task in tasks:
task.run(bot)

Expand Down
9 changes: 9 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@
RUN_TYPE = os.getenv("RUN_TYPE", "polling")

DATABASE_URL = os.getenv("DATABASE_URL", "subscribers.db")

if RUN_TYPE == "webhook":
WEBHOOK_URL = os.getenv("WEBHOOK_URL")

WEBHOOK_PATH = os.getenv("WEBHOOK_PATH", "")

WEBHOOK_HOST = os.getenv("WEBHOOK_POST", "0.0.0.0")

WEBHOOK_PORT = os.getenv("WEBHOOK_PORT", 8080)
File renamed without changes.
16 changes: 16 additions & 0 deletions docker-compose-webhook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3"
services:
bot:
build: .
environment:
- BOT_TOKEN
- WEATHER_API_KEY
- RUN_TYPE
- DATABASE_URL
- WEBHOOK_URL
- WEBHOOK_PATH
- WEBHOOK_HOST
- WEBHOOK_PORT
ports:
- ${WEBHOOK_PORT}:8080
command: python -m app

0 comments on commit 5608742

Please sign in to comment.