Update app.py
Browse files
app.py
CHANGED
|
@@ -88,6 +88,20 @@ def create_task(task: TaskData):
|
|
| 88 |
|
| 89 |
return {"status_code": response.status_code, "response": response_data}
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
@app.post("/updates")
|
| 92 |
async def task_update(request: Request):
|
| 93 |
data = await request.json()
|
|
@@ -95,7 +109,9 @@ async def task_update(request: Request):
|
|
| 95 |
|
| 96 |
event_type = data.get("event")
|
| 97 |
task_id = data.get("task_id", "Unknown ID")
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
task_link = f"https://app.clickup.com/t/{task_id}"
|
| 100 |
|
| 101 |
if event_type == "taskUpdated":
|
|
@@ -124,7 +140,13 @@ async def task_update(request: Request):
|
|
| 124 |
logging.info(f"WhatsApp API Response: {whatsapp_response.status_code} - {whatsapp_response.text}")
|
| 125 |
|
| 126 |
elif event_type == "taskTagUpdated":
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
return {"status": "Update received"}
|
|
|
|
| 88 |
|
| 89 |
return {"status_code": response.status_code, "response": response_data}
|
| 90 |
|
| 91 |
+
# Function to get task name by task ID
|
| 92 |
+
def get_task_name(task_id):
|
| 93 |
+
url = f"https://api.clickup.com/api/v2/task/{task_id}" # Replace with actual ClickUp API URL
|
| 94 |
+
headers = {"Authorization": "Bearer YOUR_CLICKUP_API_KEY"}
|
| 95 |
+
|
| 96 |
+
response = requests.get(url, headers=headers)
|
| 97 |
+
|
| 98 |
+
if response.status_code == 200:
|
| 99 |
+
task_data = response.json()
|
| 100 |
+
return task_data.get("name", "Unknown Task")
|
| 101 |
+
else:
|
| 102 |
+
logging.error(f"Failed to fetch task name for {task_id}: {response.text}")
|
| 103 |
+
return "Unknown Task"
|
| 104 |
+
|
| 105 |
@app.post("/updates")
|
| 106 |
async def task_update(request: Request):
|
| 107 |
data = await request.json()
|
|
|
|
| 109 |
|
| 110 |
event_type = data.get("event")
|
| 111 |
task_id = data.get("task_id", "Unknown ID")
|
| 112 |
+
|
| 113 |
+
# Get task name using the new function
|
| 114 |
+
task_name = get_task_name(task_id)
|
| 115 |
task_link = f"https://app.clickup.com/t/{task_id}"
|
| 116 |
|
| 117 |
if event_type == "taskUpdated":
|
|
|
|
| 140 |
logging.info(f"WhatsApp API Response: {whatsapp_response.status_code} - {whatsapp_response.text}")
|
| 141 |
|
| 142 |
elif event_type == "taskTagUpdated":
|
| 143 |
+
history_items = data.get("history_items", [])
|
| 144 |
+
if history_items:
|
| 145 |
+
for history_item in history_items:
|
| 146 |
+
if "after" in history_item:
|
| 147 |
+
for tag in history_item["after"]:
|
| 148 |
+
tag_name = tag.get("name")
|
| 149 |
+
if tag_name:
|
| 150 |
+
logging.info(f"Tag Updated: {tag_name} for Task: {task_name}")
|
| 151 |
|
| 152 |
return {"status": "Update received"}
|