Update bot.py
Browse files
bot.py
CHANGED
|
@@ -4,7 +4,7 @@ import asyncio
|
|
| 4 |
import nest_asyncio
|
| 5 |
import httpx
|
| 6 |
|
| 7 |
-
from telegram import Update
|
| 8 |
from telegram.ext import (
|
| 9 |
Application,
|
| 10 |
CommandHandler,
|
|
@@ -94,6 +94,26 @@ async def handle_message(update: Update, context: CallbackContext):
|
|
| 94 |
logger.info(f"API Response: {response_text}")
|
| 95 |
await update.message.reply_text(response_text)
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
# -------------------------
|
| 99 |
# Main function to run the bot using Webhook mode
|
|
@@ -115,7 +135,7 @@ async def main():
|
|
| 115 |
await application.run_webhook(
|
| 116 |
listen="0.0.0.0", # Listen on all available interfaces
|
| 117 |
port=443, # Port to listen on
|
| 118 |
-
|
| 119 |
webhook_url=WEBHOOK_URL # The full webhook URL that Telegram will use to send updates
|
| 120 |
)
|
| 121 |
|
|
|
|
| 4 |
import nest_asyncio
|
| 5 |
import httpx
|
| 6 |
|
| 7 |
+
from telegram import Update, Bot
|
| 8 |
from telegram.ext import (
|
| 9 |
Application,
|
| 10 |
CommandHandler,
|
|
|
|
| 94 |
logger.info(f"API Response: {response_text}")
|
| 95 |
await update.message.reply_text(response_text)
|
| 96 |
|
| 97 |
+
|
| 98 |
+
# def webhook():
|
| 99 |
+
# bot.remove_webhook()
|
| 100 |
+
# bot.set_webhook(url=WEBHOOL_URL + TOKEN) # 讛讙讚专 讗转 讛-Webhook
|
| 101 |
+
# print("webhook set: ", WEBHOOL_URL + TOKEN)
|
| 102 |
+
# return "!", 200
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# -------------------------
|
| 106 |
+
# Optional: Manually set webhook using bot.set_webhook()
|
| 107 |
+
# -------------------------
|
| 108 |
+
async def set_webhook():
|
| 109 |
+
bot = Bot(token=TOKEN)
|
| 110 |
+
# This call will set the webhook to the given URL.
|
| 111 |
+
bot_webhook = await bot.set_webhook(url=WEBHOOK_URL + TOKEN)
|
| 112 |
+
if bot_webhook:
|
| 113 |
+
logger.info(f"Webhook set successfully to: {WEBHOOK_URL}")
|
| 114 |
+
else:
|
| 115 |
+
logger.error("Failed to set webhook manually.")
|
| 116 |
+
|
| 117 |
|
| 118 |
# -------------------------
|
| 119 |
# Main function to run the bot using Webhook mode
|
|
|
|
| 135 |
await application.run_webhook(
|
| 136 |
listen="0.0.0.0", # Listen on all available interfaces
|
| 137 |
port=443, # Port to listen on
|
| 138 |
+
# url_path=TELEGRAM_WEBHOOK, # The webhook path; here, we use the bot token
|
| 139 |
webhook_url=WEBHOOK_URL # The full webhook URL that Telegram will use to send updates
|
| 140 |
)
|
| 141 |
|