measmonysuon commited on
Commit
cc6aaf9
·
verified ·
1 Parent(s): 31719cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -100,12 +100,21 @@ def handle_text_messages(message):
100
  def set_webhook():
101
  """Sets the webhook for the Telegram bot."""
102
  webhook_url = f"https://api.telegram.org/bot{BOT_TOKEN}/setWebhook?url=https://measmonysuon-flyingbird.hf.space/bot{BOT_TOKEN}"
103
- response = requests.get(webhook_url)
104
- result = response.json()
105
- if result.get('ok'):
106
- logger.info("Webhook set successfully.")
107
- else:
108
- logger.error(f"Failed to set webhook: {result}")
 
 
 
 
 
 
 
 
 
109
 
110
  if __name__ == "__main__":
111
  set_webhook() # Set the webhook before starting the Flask app
 
100
  def set_webhook():
101
  """Sets the webhook for the Telegram bot."""
102
  webhook_url = f"https://api.telegram.org/bot{BOT_TOKEN}/setWebhook?url=https://measmonysuon-flyingbird.hf.space/bot{BOT_TOKEN}"
103
+ retries = 5
104
+ while retries > 0:
105
+ try:
106
+ response = requests.get(webhook_url)
107
+ result = response.json()
108
+ if result.get('ok'):
109
+ logger.info("Webhook set successfully.")
110
+ return
111
+ else:
112
+ logger.error(f"Failed to set webhook: {result}")
113
+ except requests.exceptions.RequestException as e:
114
+ logger.error(f"Request exception: {e}")
115
+ retries -= 1
116
+ time.sleep(5) # Wait before retrying
117
+ logger.error("Failed to set webhook after multiple attempts.")
118
 
119
  if __name__ == "__main__":
120
  set_webhook() # Set the webhook before starting the Flask app