def run_webhook(self): if not WEBHOOK or not BOTTLE_PORT: raise InvalidWebhookException("Webhook is empty") request = SetWebhookRequest(url=WEBHOOK) response, content = request.do() if response.status_code != 200 or not content["ok"]: raise InvalidWebhookException("Telegram response: %s" % content) self._app = bottle.Bottle() self.map_routes() self._app.run(host=BOTTLE_HOST, port=sys.argv[1])
def run_poll(self): # disabling webhook request = SetWebhookRequest(url="") response, content = request.do() if response.status_code != 200 or not content["ok"]: raise InvalidWebhookException("Telegram response: %s" % content) while True: try: self.poll() except Exception as e: self.logger.error(str(traceback.format_exc())) self.logger.error(e) time.sleep(POLL_PERIOD)