|
from fastapi import FastAPI, Request, HTTPException,APIRouter |
|
from pydantic import BaseModel |
|
|
|
|
|
webhook_router = APIRouter(tags=["Webhooks"]) |
|
|
|
WEBHOOK_SECRET = "your_webhook_secret" |
|
|
|
class WebhookPayload(BaseModel): |
|
event: str |
|
data: dict |
|
|
|
|
|
@webhook_router.post("/webhook/sms_received/") |
|
async def handle_webhook(request: Request): |
|
|
|
|
|
|
|
payload = await request.json() |
|
event = payload.get("event") |
|
data = payload.get("data") |
|
|
|
|
|
if event == "payment_success": |
|
|
|
print("Payment was successful:", data) |
|
elif event == "user_registered": |
|
|
|
print("New user registered:", data) |
|
else: |
|
print("Received unknown event:", event) |
|
|
|
|
|
return {"status": "received"} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|