reply_to: ttypes.Message = callback.message.reply_to_message file_type, book_id = reply_to.text.replace('/', '').split('_') sender.remove_cache(file_type, int(book_id)) msg.wait() sender.send_book(reply_to, int(book_id), file_type) async def handle(request): if request.match_info.get('token') == bot.token: request_body_dict = await request.json() bot.process_new_updates([ttypes.Update.de_json(request_body_dict)]) global last_update last_update = time.time() return web.Response() else: return web.Response(status=403) if __name__ == "__main__": bot.remove_webhook() app = web.Application() app.router.add_post('/{token}/', handle) WEBHOOK_URL_BASE = config.WEBHOOK_HOST WEBHOOK_URL_PATH = "/{}/".format(config.BOT_TOKEN) bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH) web.run_app(app, host=config.SERVER_HOST, port=config.SERVER_PORT)
from django.conf import settings from ..dbmodels.auth import ScheduleUser import time from telebot import AsyncTeleBot, logger, types import logging __author__ = "@schedulebase_bot" logger.setLevel(settings.LOG_LEVEL) bot = AsyncTeleBot(settings.TOKEN) bot.threaded = True settings.BOT = bot bot.remove_webhook() logging.info("Removed previous webhook") time.sleep(1) bot.set_webhook(url=f"{settings.DOMAIN}/bot/") logging.info("Set new webhook") logging.info(f"Webhook info: {bot.get_webhook_info()}")