Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -6,18 +6,12 @@ from telegram.ext._contexttypes import ContextTypes
|
|
6 |
from fastapi import FastAPI, Request, Response
|
7 |
|
8 |
# Initialize python telegram bot
|
9 |
-
|
10 |
-
|
11 |
-
.updater(None)
|
12 |
-
.token('7163529766:AAGGGlSjVqtcm_b0vJJu7sU9Y7VzSzeYNZg') # replace <your-bot-token>
|
13 |
-
.read_timeout(7)
|
14 |
-
.get_updates_read_timeout(42)
|
15 |
-
.build()
|
16 |
-
)
|
17 |
|
18 |
@asynccontextmanager
|
19 |
async def lifespan(_: FastAPI):
|
20 |
-
await ptb.bot.setWebhook('https://manishx-telegrambot.hf.space
|
21 |
async with ptb:
|
22 |
await ptb.start()
|
23 |
yield
|
@@ -27,8 +21,8 @@ async def lifespan(_: FastAPI):
|
|
27 |
app = FastAPI(lifespan=lifespan)
|
28 |
|
29 |
@app.get("/")
|
30 |
-
def read_general():
|
31 |
-
return {"response": "Started"}
|
32 |
|
33 |
@app.post("/")
|
34 |
async def process_update(request: Request):
|
@@ -39,11 +33,9 @@ async def process_update(request: Request):
|
|
39 |
await ptb.process_update(update)
|
40 |
return Response(status_code=HTTPStatus.OK)
|
41 |
|
42 |
-
|
43 |
-
|
44 |
# Example handler
|
45 |
async def start(update, _: ContextTypes.DEFAULT_TYPE):
|
46 |
"""Send a message when the command /start is issued."""
|
47 |
await update.message.reply_text("starting...")
|
48 |
|
49 |
-
ptb.add_handler(CommandHandler("start", start))
|
|
|
6 |
from fastapi import FastAPI, Request, Response
|
7 |
|
8 |
# Initialize python telegram bot
|
9 |
+
bot_token = '7163529766:AAGGGlSjVqtcm_b0vJJu7sU9Y7VzSzeYNZg' # replace <your-bot-token>
|
10 |
+
ptb = Application(bot_token=bot_token, read_timeout=7, get_updates_read_timeout=42)
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
@asynccontextmanager
|
13 |
async def lifespan(_: FastAPI):
|
14 |
+
await ptb.bot.setWebhook('https://manishx-telegrambot.hf.space') # replace <your-webhook-url>
|
15 |
async with ptb:
|
16 |
await ptb.start()
|
17 |
yield
|
|
|
21 |
app = FastAPI(lifespan=lifespan)
|
22 |
|
23 |
@app.get("/")
|
24 |
+
def read_general():
|
25 |
+
return {"response": "Started"}
|
26 |
|
27 |
@app.post("/")
|
28 |
async def process_update(request: Request):
|
|
|
33 |
await ptb.process_update(update)
|
34 |
return Response(status_code=HTTPStatus.OK)
|
35 |
|
|
|
|
|
36 |
# Example handler
|
37 |
async def start(update, _: ContextTypes.DEFAULT_TYPE):
|
38 |
"""Send a message when the command /start is issued."""
|
39 |
await update.message.reply_text("starting...")
|
40 |
|
41 |
+
ptb.add_handler(CommandHandler("start", start))
|