randydev commited on
Commit
ecf3d1e
·
verified ·
1 Parent(s): c5b19bf

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -7
main.py CHANGED
@@ -8,6 +8,8 @@ logger = logging.getLogger(__name__)
8
  LOGS = logging.getLogger("[akenox]")
9
  logger.setLevel(logging.DEBUG)
10
 
 
 
11
  client = js.create_pyrogram(
12
  name="fastapi-bot",
13
  api_id=API_ID,
@@ -15,17 +17,18 @@ client = js.create_pyrogram(
15
  bot_token=BOT_TOKEN
16
  )
17
 
18
- @asynccontextmanager
19
- async def lifespan(app: js.get_app()):
20
  user = await client.start()
21
- LOGS.info(f"Started UserBot: {user.me.first_name}")
22
- yield
23
 
24
- app = js.get_app(lifespan=lifespan)
 
 
25
 
26
- @app.get("/api/send")
27
  async def send_message():
28
  response_json = await client.send_message("@xpushz", "hello world!")
29
  return {"success": response_json}
30
 
31
- run_fast(port=7860)
 
8
  LOGS = logging.getLogger("[akenox]")
9
  logger.setLevel(logging.DEBUG)
10
 
11
+ fast_app = js.get_app()
12
+
13
  client = js.create_pyrogram(
14
  name="fastapi-bot",
15
  api_id=API_ID,
 
17
  bot_token=BOT_TOKEN
18
  )
19
 
20
+ @fast_app.on_event("startup")
21
+ async def startup_event():
22
  user = await client.start()
23
+ LOGS.info(f"Started Bot: {user.me.first_name}")
 
24
 
25
+ @fast_app.get("/")
26
+ async def hello():
27
+ return {"success": response_json}
28
 
29
+ @fast_app.get("/api/send")
30
  async def send_message():
31
  response_json = await client.send_message("@xpushz", "hello world!")
32
  return {"success": response_json}
33
 
34
+ run_fast(build=fast_app, port=7860)