Skip to content

Commit

Permalink
Join random token with webhook path on startup
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Nov 9, 2019
1 parent 39a6c39 commit f85358b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with TellerBot. If not, see <https://www.gnu.org/licenses/>.
import asyncio
import secrets

from aiogram.utils import executor

Expand All @@ -25,14 +26,13 @@
from src.registered_handlers import tg


async def on_startup(*args):
async def on_startup(webhook_path, *args):
"""Prepare bot before starting.
Set webhook and run background tasks.
"""
await tg.delete_webhook()
url = 'https://{}'.format(config.SERVER_HOST)
await tg.set_webhook(url + config.WEBHOOK_PATH)
await tg.set_webhook('https://' + config.SERVER_HOST + webhook_path)
asyncio.create_task(notifications.run_loop())
asyncio.create_task(connect_to_blockchains())

Expand All @@ -42,10 +42,13 @@ def main():
Bot's main entry point.
"""
url_token = secrets.token_urlsafe()
webhook_path = config.WEBHOOK_PATH + '/' + url_token

executor.start_webhook(
dispatcher=dp,
webhook_path=config.WEBHOOK_PATH,
on_startup=on_startup,
webhook_path=webhook_path,
on_startup=lambda *args: on_startup(webhook_path, *args),
host='127.0.0.1',
port=config.SERVER_PORT,
)
Expand Down

0 comments on commit f85358b

Please sign in to comment.