-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (32 loc) · 1003 Bytes
/
app.py
File metadata and controls
40 lines (32 loc) · 1003 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
36
37
38
39
40
import uvicorn
import traceback
from typing import List
from mangum import Mangum
from pydantic import BaseModel
from starlette.requests import Request
from fastapi import FastAPI, HTTPException
from starlette.middleware.cors import CORSMiddleware
from models import NotifyRequest
from notifiers import Notifier, router
app = FastAPI()
app.include_router(router)
@app.post("/notify")
async def notify(request: NotifyRequest):
resps = []
for notifier in request.notifiers:
try:
resp = await Notifier.notifiers[notifier.name].notify(
request.title,
request.body,
**notifier.payload)
resps.append(resp)
except Exception as e:
resps.append({
'name': notifier.name,
'status': 'error',
'message': repr(e)
})
return resps
handler = Mangum(app, enable_lifespan=False)
if __name__ == '__main__':
uvicorn.run(app, host='0.0.0.0')