From 2471346647819b19ca99fc01aed019e6ef183f49 Mon Sep 17 00:00:00 2001 From: infinity-plus Date: Sat, 13 Mar 2021 00:09:42 +0530 Subject: [PATCH] Switch to Webhooks Signed-off-by: infinity-plus --- app.json | 3 +++ bot.py | 7 +++++-- config.py | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app.json b/app.json index a01bfd4..c979eff 100644 --- a/app.json +++ b/app.json @@ -20,6 +20,9 @@ }, "sheet2": { "description": "API key from https://sheet.best" + }, + "heroku": { + "description": "Heroku app link. Type App Name to get link." } } } \ No newline at end of file diff --git a/bot.py b/bot.py index 51050b3..a285e04 100644 --- a/bot.py +++ b/bot.py @@ -46,7 +46,10 @@ def initilize(self): dispatcher.add_handler(RolesHandler( stop_button_handler, roles.chat_admins)) - updater.start_polling() + updater.start_webhook(listen="0.0.0.0", + port=int(Config.PORT), + url_path=self.TOKEN) + updater.bot.setWebhook(Config.heroku + self.TOKEN) def start(self, update, context): context.bot.send_message( @@ -174,7 +177,7 @@ def stop_quiz(self, update, context): logger = logging.getLogger(__name__) logging.basicConfig( format='%(levelname)s:%(asctime)s:%(filename)s,%(lineno)d:%(name)s.%(funcName)s:%(message)s', level=logging.WARN) - if not (Config.api == "None" or Config.sheet1 == "None" or Config.sheet2 == "None"): + if not (Config.api == "None" or Config.sheet1 == "None" or Config.sheet2 == "None" or Config.heroku == "None"): quiz_bot = Quiz(Config.api) quiz_bot.initilize() else: diff --git a/config.py b/config.py index b3ab74d..0df246c 100644 --- a/config.py +++ b/config.py @@ -7,3 +7,5 @@ class Config: api: str = environ.get("api", "None") sheet1: str = environ.get("sheet1", "None") sheet2: str = environ.get("sheet2", "None") + heroku: str = environ.get("heroku", "None") + PORT: int = int(environ.get('PORT', 5000))