Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,19 @@
|
|
| 1 |
-
from fastapi import FastAPI, Request
|
| 2 |
-
from telegram import Update, Bot
|
|
|
|
| 3 |
from telegram.ext import Dispatcher, MessageHandler, Filters
|
| 4 |
import os
|
| 5 |
|
| 6 |
TOKEN = os.getenv("TELEGRAM_TOKEN")
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
bot = Bot(token=TOKEN, request=request)
|
| 13 |
dispatcher = Dispatcher(bot, None, use_context=True)
|
| 14 |
|
| 15 |
def handle_message(update: Update, context):
|
| 16 |
-
# برای اطمینان از اینکه تابع اجرا میشود، میتوانید لاگ بگیرید
|
| 17 |
print(f"Received message: {update.message.text}")
|
| 18 |
update.message.reply_text(f"سلام! تو گفتی: {update.message.text}")
|
| 19 |
|
|
@@ -26,7 +26,7 @@ async def root():
|
|
| 26 |
return {"status": "running"}
|
| 27 |
|
| 28 |
@app.post("/webhook")
|
| 29 |
-
async def webhook(request:
|
| 30 |
update = Update.de_json(await request.json(), bot)
|
| 31 |
dispatcher.process_update(update)
|
| 32 |
return {"status": "ok"}
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request as FastAPIRequest
|
| 2 |
+
from telegram import Update, Bot
|
| 3 |
+
from telegram.utils.request import Request # ایمپورت صحیح برای نسخه 13.7
|
| 4 |
from telegram.ext import Dispatcher, MessageHandler, Filters
|
| 5 |
import os
|
| 6 |
|
| 7 |
TOKEN = os.getenv("TELEGRAM_TOKEN")
|
| 8 |
|
| 9 |
+
# ایجاد آبجکت درخواست با زمان انتظار بیشتر
|
| 10 |
+
# نام متغیر را tg_request گذاشتم تا با FastAPIRequest تداخل نداشته باشد
|
| 11 |
+
tg_request = Request(connect_timeout=20.0, read_timeout=20.0)
|
| 12 |
|
| 13 |
+
bot = Bot(token=TOKEN, request=tg_request)
|
|
|
|
| 14 |
dispatcher = Dispatcher(bot, None, use_context=True)
|
| 15 |
|
| 16 |
def handle_message(update: Update, context):
|
|
|
|
| 17 |
print(f"Received message: {update.message.text}")
|
| 18 |
update.message.reply_text(f"سلام! تو گفتی: {update.message.text}")
|
| 19 |
|
|
|
|
| 26 |
return {"status": "running"}
|
| 27 |
|
| 28 |
@app.post("/webhook")
|
| 29 |
+
async def webhook(request: FastAPIRequest):
|
| 30 |
update = Update.de_json(await request.json(), bot)
|
| 31 |
dispatcher.process_update(update)
|
| 32 |
return {"status": "ok"}
|