-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
64 lines (57 loc) · 2.41 KB
/
app.py
File metadata and controls
64 lines (57 loc) · 2.41 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from fastapi import FastAPI, Request, HTTPException, BackgroundTasks
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
import json
import os
import asyncio
from datetime import datetime
from slack_events import slack_event_handler
from slack_credentials_manager import credentials_manager
from workflow_manager import workflow_manager
app = FastAPI(title="AI Slack Bot Builder", version="1.0.0")
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/api/health")
async def health_check():
"""Health check endpoint"""
credentials_summary = credentials_manager.get_credentials_summary()
workflows_summary = workflow_manager.get_workflows_summary()
return {
"status": "healthy",
"message": "AI Slack Bot Builder is running",
"credentials": credentials_summary,
"workflows": workflows_summary
}
# Slack Interactive endpoint
@app.post("/api/slack/interactive")
async def handle_slack_interactive(request: Request):
"""Handle Slack interactive components"""
try:
# For now, just return a success response
# This can be expanded later for handling interactive components
return {"status": "success"}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.post("/api/slack/events")
async def handle_slack_events(request: Request, background_tasks: BackgroundTasks):
"""Handle Slack event subscriptions"""
try:
request_data = await request.json()
if 'x-slack-retry-num' in request.headers or 'x-slack-retry-reason' in request.headers:
print('Retry from Slack:' + str(request.headers['x-slack-retry-num']) + ' ' + str(request.headers['x-slack-retry-reason']))
# Return 200 immediately and process in background
background_tasks.add_task(slack_event_handler.handle_event_async, request_data, request)
if request_data.get('type') == 'url_verification':
return JSONResponse({"status": "accepted", "challenge": request_data.get('challenge')}, status_code=200)
return JSONResponse({"status": "accepted"}, status_code=200)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5000)