Update app.py
Browse files
app.py
CHANGED
|
@@ -117,22 +117,21 @@ async def task_update(request: Request):
|
|
| 117 |
event_type = data.get("event")
|
| 118 |
task_id = data.get("task_id", "Unknown ID")
|
| 119 |
|
| 120 |
-
# Get task
|
| 121 |
task_name = get_task_name(task_id)
|
| 122 |
task_link = f"https://app.clickup.com/t/{task_id}"
|
| 123 |
|
| 124 |
if event_type == "taskUpdated":
|
| 125 |
-
# Extract history items
|
| 126 |
history_items = data.get("history_items", [])
|
| 127 |
|
| 128 |
for item in history_items:
|
| 129 |
-
if item.get("field") == "status":
|
| 130 |
after_status = item.get("after", {}).get("status")
|
| 131 |
action_timestamp = item.get("date", 0)
|
| 132 |
|
| 133 |
if not after_status:
|
| 134 |
logging.warning(f"Task {task_id} update ignored: No status change detected.")
|
| 135 |
-
continue
|
| 136 |
|
| 137 |
action_date_human = datetime.utcfromtimestamp(int(action_timestamp) / 1000).strftime('%Y-%m-%d %H:%M:%S') if action_timestamp else "Unknown Date"
|
| 138 |
|
|
@@ -158,7 +157,24 @@ async def task_update(request: Request):
|
|
| 158 |
if "after" in history_item:
|
| 159 |
for tag in history_item["after"]:
|
| 160 |
tag_name = tag.get("name")
|
| 161 |
-
if tag_name:
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
return {"status": "Update received"}
|
|
|
|
| 117 |
event_type = data.get("event")
|
| 118 |
task_id = data.get("task_id", "Unknown ID")
|
| 119 |
|
| 120 |
+
# Get task details
|
| 121 |
task_name = get_task_name(task_id)
|
| 122 |
task_link = f"https://app.clickup.com/t/{task_id}"
|
| 123 |
|
| 124 |
if event_type == "taskUpdated":
|
|
|
|
| 125 |
history_items = data.get("history_items", [])
|
| 126 |
|
| 127 |
for item in history_items:
|
| 128 |
+
if item.get("field") == "status":
|
| 129 |
after_status = item.get("after", {}).get("status")
|
| 130 |
action_timestamp = item.get("date", 0)
|
| 131 |
|
| 132 |
if not after_status:
|
| 133 |
logging.warning(f"Task {task_id} update ignored: No status change detected.")
|
| 134 |
+
continue
|
| 135 |
|
| 136 |
action_date_human = datetime.utcfromtimestamp(int(action_timestamp) / 1000).strftime('%Y-%m-%d %H:%M:%S') if action_timestamp else "Unknown Date"
|
| 137 |
|
|
|
|
| 157 |
if "after" in history_item:
|
| 158 |
for tag in history_item["after"]:
|
| 159 |
tag_name = tag.get("name")
|
| 160 |
+
if tag_name and tag_name.lower() == "missed due date":
|
| 161 |
+
# Get due date
|
| 162 |
+
task_details = get_task_details(task_id) # Function to fetch task details
|
| 163 |
+
due_date_timestamp = task_details.get("due_date")
|
| 164 |
+
due_date = datetime.utcfromtimestamp(int(due_date_timestamp) / 1000).strftime('%Y-%m-%d') if due_date_timestamp else "Unknown Due Date"
|
| 165 |
+
|
| 166 |
+
logging.info(f"Missed Due Date Tag Added for Task: {task_name}, Due Date: {due_date}")
|
| 167 |
+
|
| 168 |
+
whatsapp_payload = {
|
| 169 |
+
"chatId": "201092003112@c.us",
|
| 170 |
+
"message": f"⚠️ *Task Missed Due Date!*\n\n📌 *Task:* {task_name}\n📅 *Due Date:* {due_date}\n\n🔗 *View Task:* {task_link}\n\nPlease take action immediately."
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
try:
|
| 174 |
+
whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
|
| 175 |
+
whatsapp_response.raise_for_status()
|
| 176 |
+
logging.info(f"WhatsApp API Response: {whatsapp_response.status_code} - {whatsapp_response.text}")
|
| 177 |
+
except requests.RequestException as e:
|
| 178 |
+
logging.error(f"Failed to send WhatsApp notification: {e}")
|
| 179 |
|
| 180 |
return {"status": "Update received"}
|