Объясните тонкости, что упускаю, тестировал работу через localtunnel (
https://localtunnel.github.io/www/) все ок, а на хостинге запустить не выходит.
Статус вебхука:
{"ok":true,"result":{"url":"
https://mydomen.ru"
,"has_custom_certificate":false,
"pending_update_count":40,
"last_error_date":1705299223,
"last_error_message":"Wrong response from the webhook: 403 Forbidden",
"max_connections":40,
"ip_address":"111.11.11.111",
"allowed_updates":["message","callback_query"]}}
import logging
from typing import Any, Dict, Union
from aiogram import Bot, Dispatcher
from aiogram.client.session.aiohttp import AiohttpSession
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.fsm.strategy import FSMStrategy
from aiogram.utils.token import TokenValidationError, validate_token
from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_application
from aiohttp import web
from bot.handlers import *
from load_env import token
BASE_URL = "mydomen.ru"
MAIN_BOT_TOKEN = token
WEB_SERVER_HOST = "127.0.0.1"
WEB_SERVER_PORT = 8350
MAIN_BOT_PATH = ""
logging.basicConfig(level=logging.INFO)
def is_bot_token(value: str) -> Union[bool, Dict[str, Any]]:
try:
validate_token(value)
except TokenValidationError:
return False
return True
async def on_startup(bot: Bot):
await bot.set_webhook(f"{BASE_URL}{MAIN_BOT_PATH}")
def webhook():
app = web.Application()
session = AiohttpSession()
bot_settings = {"token": MAIN_BOT_TOKEN, "session": session, "parse_mode": "Markdown"}
bot = Bot(**bot_settings)
dp = Dispatcher(storage=MemoryStorage(), fsm_strategy=FSMStrategy.USER_IN_CHAT) # FSM !
dp.startup.register(on_startup)
dp.include_router(handler_common.router)
dp.include_router(handler_create_filter.router)
dp.include_router(handler_callback.router)
dp.include_router(handler_filters.router)
dp.include_router(handler_price_tracking.router)
dp.include_router(handler_edit_filter.router)
dp.include_router(handler_admin.router)
SimpleRequestHandler(dispatcher=dp, bot=bot).register(app, path=MAIN_BOT_PATH)
setup_application(app, dp, bot=bot)
web.run_app(app, host=WEB_SERVER_HOST, port=WEB_SERVER_PORT)
if __name__ == "__main__":
webhook()