File size: 853 Bytes
627fc60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, Request
import uvicorn

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "TEST BOT", "status": "working"}

@app.get("/health")
async def health():
    return {"status": "healthy"}

@app.post("/whatsapp-webhook")
async def webhook(request: Request):
    try:
        form_data = await request.form()
        from_number = form_data.get('From', 'unknown')
        body = form_data.get('Body', 'empty')
        print(f"MESAJ: {from_number} -> {body}")
        return {"status": "received", "message": f"Got: {body}"}
    except Exception as e:
        print(f"ERROR: {e}")
        return {"status": "error"}

@app.get("/whatsapp-webhook")
async def webhook_get():
    return {"message": "Webhook çalışıyor", "method": "GET"}

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)