Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
import uvicorn
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
@app.get("/")
|
7 |
+
async def root():
|
8 |
+
return {"message": "TEST BOT", "status": "working"}
|
9 |
+
|
10 |
+
@app.get("/health")
|
11 |
+
async def health():
|
12 |
+
return {"status": "healthy"}
|
13 |
+
|
14 |
+
@app.post("/whatsapp-webhook")
|
15 |
+
async def webhook(request: Request):
|
16 |
+
try:
|
17 |
+
form_data = await request.form()
|
18 |
+
from_number = form_data.get('From', 'unknown')
|
19 |
+
body = form_data.get('Body', 'empty')
|
20 |
+
print(f"MESAJ: {from_number} -> {body}")
|
21 |
+
return {"status": "received", "message": f"Got: {body}"}
|
22 |
+
except Exception as e:
|
23 |
+
print(f"ERROR: {e}")
|
24 |
+
return {"status": "error"}
|
25 |
+
|
26 |
+
@app.get("/whatsapp-webhook")
|
27 |
+
async def webhook_get():
|
28 |
+
return {"message": "Webhook çalışıyor", "method": "GET"}
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|