2025-01-08 13:55:59 +03:00
|
|
|
import logging
|
|
|
|
import sys
|
2024-08-25 18:04:34 +03:00
|
|
|
|
|
|
|
import yaml
|
2024-08-25 22:16:23 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
from aiohttp import web
|
2024-10-29 20:05:50 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
from aiogram import Bot, Dispatcher, Router
|
|
|
|
from aiogram.client.default import DefaultBotProperties
|
|
|
|
from aiogram.enums import ParseMode
|
|
|
|
from aiogram.filters import CommandStart
|
|
|
|
from aiogram.types import Message
|
|
|
|
from aiogram.utils.markdown import hbold
|
|
|
|
from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_application
|
2023-03-08 13:31:45 +03:00
|
|
|
|
2024-11-13 17:35:23 +03:00
|
|
|
config = yaml.safe_load(open('config.yaml'))
|
2023-03-08 13:31:45 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
router = Router()
|
2023-03-08 13:31:45 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
@router.message()
|
|
|
|
async def echo_handler(message: Message) -> None:
|
2023-03-08 13:31:45 +03:00
|
|
|
try:
|
2025-01-08 13:55:59 +03:00
|
|
|
# Send a copy of the received message
|
|
|
|
await message.send_copy(chat_id=message.chat.id)
|
|
|
|
except TypeError:
|
|
|
|
# But not all the types is supported to be copied so need to handle it
|
|
|
|
await message.answer("Nice try!")
|
2024-11-13 17:35:23 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
async def on_startup(bot: Bot) -> None:
|
|
|
|
# Убедитесь, что передаете HTTPS URL
|
|
|
|
await bot.set_webhook(f"{config['webhook']['base_url']}{config['webhook']['path']}", secret_token=config['webhook']['secret_token'])
|
2024-08-29 16:54:52 +03:00
|
|
|
|
2024-11-13 17:35:23 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
def main() -> None:
|
|
|
|
dp = Dispatcher()
|
2024-08-29 16:54:52 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
dp.include_router(router)
|
|
|
|
dp.startup.register(on_startup)
|
|
|
|
|
|
|
|
bot = Bot(token=config['telegram_token'], default=DefaultBotProperties(parse_mode=ParseMode.HTML))
|
2024-08-29 16:54:52 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
app = web.Application()
|
|
|
|
webhook_requests_handler = SimpleRequestHandler(
|
|
|
|
dispatcher=dp,
|
|
|
|
bot=bot,
|
|
|
|
secret_token=config['webhook']['secret_token']
|
|
|
|
)
|
|
|
|
webhook_requests_handler.register(app, path=config['webhook']['path'])
|
2024-08-29 16:54:52 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
setup_application(app, dp, bot=bot)
|
2024-11-28 21:50:52 +03:00
|
|
|
|
2025-01-08 13:55:59 +03:00
|
|
|
web.run_app(app, host='127.0.0.1', port=8080)
|
2023-09-29 21:12:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2025-01-08 13:55:59 +03:00
|
|
|
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
|
|
|
|
main()
|