-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
35 lines (27 loc) · 974 Bytes
/
server.py
File metadata and controls
35 lines (27 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI
from pydantic import BaseModel
import httpx
from config.config import settings
from graph import run_graph
from models.domain import User
BOT_TOKEN = settings.BOT_TOKEN
TELEGRAM_API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}"
app = FastAPI()
class TelegramUpdate(BaseModel):
update_id: int
message: dict
@app.post("/webhook")
async def telegram_webhook(update: TelegramUpdate):
message = update.message
chat_id = message["chat"]["id"]
text = message.get("text", "")
# TODO: Replace with a real user object
user = User(name="Rohan Paul", email="rohan1007rjp@gmail.com", interests=["running", "coding"],home_city="Chennai")
result = await run_graph(text, user)
# Send result back to Telegram
async with httpx.AsyncClient() as client:
await client.post(
f"{TELEGRAM_API_URL}/sendMessage",
json={"chat_id": chat_id, "text": result}
)
return {"ok": True}