Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import logging
- import ssl
- from aiogram import Bot, types
- from aiogram.dispatcher import Dispatcher
- from aiogram.utils.executor import start_webhook
- API_TOKEN = 'token'
- # webhook settings
- WEBHOOK_HOST = '0.0.0.0' #если при создании сертификата был указан домен то он должен совпадать
- WEBHOOK_PORT = 8443 # 443, 80, 88 or 8443 (port need to be 'open')
- WEBHOOK_SSL_CERT = '/yours_server/cert/YOURPUBLIC.pem' # Path to the ssl certificate
- WEBHOOK_SSL_PRIV = '/yours_server/cert/YOURPRIVATE.key' # Path to the ssl private key
- WEBHOOK_URL_BASE = "https://{}:{}".format(WEBHOOK_HOST, WEBHOOK_PORT)
- WEBHOOK_URL_PATH = "/{}/".format(API_TOKEN)
- logging.basicConfig(level=logging.INFO)
- bot = Bot(token=API_TOKEN)
- dp = Dispatcher(bot)
- context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
- context.load_cert_chain(WEBHOOK_SSL_CERT, WEBHOOK_SSL_PRIV)
- @dp.message_handler()
- async def echo(message: types.Message):
- await bot.send_message(message.chat.id, message.text)
- async def on_startup(dp):
- await bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
- certificate=open(WEBHOOK_SSL_CERT, 'r'))
- async def on_shutdown(dp):
- pass
- if __name__ == '__main__':
- start_webhook(dispatcher=dp, webhook_path=WEBHOOK_URL_PATH,
- on_startup=on_startup, on_shutdown=on_shutdown,
- skip_updates=True, host=WEBHOOK_HOST, port=WEBHOOK_PORT,
- ssl_context=context,)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement