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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -16,6 +16,7 @@ BOT_TOKEN = '7484321656:AAFaswxTqaSHu_s4jd_pk2Q2OJJWYcWHwAM'
16
  # Initialize the Telegram bot
17
  bot = telebot.TeleBot(BOT_TOKEN)
18
 
 
19
  # Configure logging
20
  logging.basicConfig(
21
  level=logging.DEBUG,
@@ -96,5 +97,16 @@ def handle_text_messages(message):
96
  bot.send_message(message.chat.id, error_message, parse_mode='Markdown')
97
  logger.error(f"Error message sent to chat_id {message.chat.id}")
98
 
 
 
 
 
 
 
 
 
 
 
99
  if __name__ == "__main__":
 
100
  app.run(host='0.0.0.0', port=5000)
 
16
  # Initialize the Telegram bot
17
  bot = telebot.TeleBot(BOT_TOKEN)
18
 
19
+
20
  # Configure logging
21
  logging.basicConfig(
22
  level=logging.DEBUG,
 
97
  bot.send_message(message.chat.id, error_message, parse_mode='Markdown')
98
  logger.error(f"Error message sent to chat_id {message.chat.id}")
99
 
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
112
  app.run(host='0.0.0.0', port=5000)