Update bot.py
Browse files
bot.py
CHANGED
|
@@ -107,15 +107,16 @@ async def handle_message(update: Update, context: CallbackContext):
|
|
| 107 |
# -------------------------
|
| 108 |
async def set_webhook():
|
| 109 |
bot = Bot(token=TOKEN)
|
|
|
|
| 110 |
# This call will set the webhook to the given URL.
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 113 |
logger.info(f"Webhook set successfully to: {WEBHOOK_URL}")
|
| 114 |
print("bot webhook success")
|
| 115 |
-
|
| 116 |
-
logger.error("Failed to set webhook manually.")
|
| 117 |
-
print("error setting bot webhook")
|
| 118 |
-
|
| 119 |
|
| 120 |
# -------------------------
|
| 121 |
# Main function to run the bot using Webhook mode
|
|
@@ -137,8 +138,8 @@ async def main():
|
|
| 137 |
await application.run_webhook(
|
| 138 |
listen="0.0.0.0", # Listen on all available interfaces
|
| 139 |
port=443, # Port to listen on
|
| 140 |
-
|
| 141 |
-
webhook_url=WEBHOOK_URL # The full webhook URL that Telegram will use to send updates
|
| 142 |
)
|
| 143 |
|
| 144 |
|
|
|
|
| 107 |
# -------------------------
|
| 108 |
async def set_webhook():
|
| 109 |
bot = Bot(token=TOKEN)
|
| 110 |
+
bot.remove_webhook()
|
| 111 |
# This call will set the webhook to the given URL.
|
| 112 |
+
PATH = WEBHOOK_URL + TOKEN
|
| 113 |
+
try:
|
| 114 |
+
await bot.set_webhook(url=PATH)
|
| 115 |
logger.info(f"Webhook set successfully to: {WEBHOOK_URL}")
|
| 116 |
print("bot webhook success")
|
| 117 |
+
except Exception as e:
|
| 118 |
+
logger.error(f"Failed to set webhook manually. Error: {e}")
|
| 119 |
+
print(f"error setting bot webhook. Error: {e}")
|
|
|
|
| 120 |
|
| 121 |
# -------------------------
|
| 122 |
# Main function to run the bot using Webhook mode
|
|
|
|
| 138 |
await application.run_webhook(
|
| 139 |
listen="0.0.0.0", # Listen on all available interfaces
|
| 140 |
port=443, # Port to listen on
|
| 141 |
+
# url_path=TELEGRAM_WEBHOOK, # The webhook path; here, we use the bot token
|
| 142 |
+
#webhook_url=WEBHOOK_URL # The full webhook URL that Telegram will use to send updates
|
| 143 |
)
|
| 144 |
|
| 145 |
|