Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WEBHOOK_URL = f'{WEBHOOK_HOST}:{WEBHOOK_PORT}{WEBHOOK_URL_PATH}'
- async def on_startup(app):
- # Check webhook
- webhook = await bot.get_webhook_info()
- # If URL is bad
- if webhook.url != WEBHOOK_URL:
- # If URL doesnt match current - remove webhook
- if not webhook.url:
- await bot.delete_webhook()
- # Set new URL for webhook
- await bot.set_webhook(WEBHOOK_URL, certificate=open(WEBHOOK_SSL_CERT, 'rb').read())
- async def on_shutdown(app):
- # insert code here to run it before shutdown
- await bot.close()
- # Remove webhook (not acceptable in some cases)
- await bot.delete_webhook()
- # Close DB connection (if used)
- await dp.storage.close()
- await dp.storage.wait_closed()
- if __name__ == '__main__':
- # пробрасываем dp через handlers сюда
- from handlers_purchase import dp
- from handlers_newuser import dp
- from handlers_subscriber_ import dp
- from handlers_admin import dp
- from handlers_start import dp
- app = get_new_configured_app(dispatcher=dp, path=WEBHOOK_URL_PATH)
- # Setup event handlers.
- app.on_startup.append(on_startup)
- app.on_shutdown.append(on_shutdown)
- # Generate SSL context.
- context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
- context.load_cert_chain(WEBHOOK_SSL_CERT, WEBHOOK_SSL_PRIV)
- # Start web-application
- web.run_app(app, host=WEBAPP_HOST, port=WEBAPP_PORT, ssl_context=context)
Advertisement
Add Comment
Please, Sign In to add comment