Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook implementation #48

Merged
merged 4 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading