first commit

This commit is contained in:
2026-07-14 13:38:43 +07:00
commit 8b0e1ffffa
19 changed files with 836 additions and 0 deletions

47
app/telegram.py Normal file
View File

@@ -0,0 +1,47 @@
from __future__ import annotations
from aiogram import Bot
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from app.models import Offer
class TelegramPublisher:
def __init__(self, bot: Bot, channel_id: str) -> None:
self._bot = bot
self._channel_id = channel_id
async def publish_offer(self, offer: Offer) -> None:
await self._bot.send_message(
chat_id=self._channel_id,
text=_format_offer_message(offer),
disable_web_page_preview=True,
reply_markup=_build_delete_markup(),
)
def _format_offer_message(offer: Offer) -> str:
seller_line = f"Исполнитель: @{offer.seller_username}\n" if offer.seller_username else ""
description = offer.description.strip()
if len(description) > 1000:
description = f"{description[:997].rstrip()}..."
return (
f"Новый оффер: {offer.title}\n"
f"Источник: {offer.source}\n"
f"Категория: {offer.category_id}\n"
f"Бюджет: {offer.price}\n"
f"Опубликовано: {offer.published_at}\n"
f"{seller_line}"
f"\n"
f"{description}\n\n"
f"Ссылка: {offer.url}"
)
def _build_delete_markup() -> InlineKeyboardMarkup:
return InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(text="❌", callback_data="delete_post")]
]
)