Guest User

Untitled

a guest
May 25th, 2020
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1.  
  2. WEBHOOK_URL = f'{WEBHOOK_HOST}:{WEBHOOK_PORT}{WEBHOOK_URL_PATH}'
  3.  
  4.  
  5. async def on_startup(app):
  6.  
  7. # Check webhook
  8. webhook = await bot.get_webhook_info()
  9.  
  10. # If URL is bad
  11. if webhook.url != WEBHOOK_URL:
  12. # If URL doesnt match current - remove webhook
  13. if not webhook.url:
  14. await bot.delete_webhook()
  15.  
  16. # Set new URL for webhook
  17. await bot.set_webhook(WEBHOOK_URL, certificate=open(WEBHOOK_SSL_CERT, 'rb').read())
  18.  
  19.  
  20. async def on_shutdown(app):
  21. # insert code here to run it before shutdown
  22. await bot.close()
  23.  
  24. # Remove webhook (not acceptable in some cases)
  25. await bot.delete_webhook()
  26.  
  27. # Close DB connection (if used)
  28. await dp.storage.close()
  29. await dp.storage.wait_closed()
  30.  
  31.  
  32. if __name__ == '__main__':
  33. # пробрасываем dp через handlers сюда
  34. from handlers_purchase import dp
  35. from handlers_newuser import dp
  36. from handlers_subscriber_ import dp
  37. from handlers_admin import dp
  38. from handlers_start import dp
  39.  
  40. app = get_new_configured_app(dispatcher=dp, path=WEBHOOK_URL_PATH)
  41.  
  42. # Setup event handlers.
  43. app.on_startup.append(on_startup)
  44. app.on_shutdown.append(on_shutdown)
  45.  
  46. # Generate SSL context.
  47. context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
  48. context.load_cert_chain(WEBHOOK_SSL_CERT, WEBHOOK_SSL_PRIV)
  49.  
  50. # Start web-application
  51. web.run_app(app, host=WEBAPP_HOST, port=WEBAPP_PORT, ssl_context=context)
Advertisement
Add Comment
Please, Sign In to add comment