Update app.py
Browse files
app.py
CHANGED
|
@@ -117,34 +117,39 @@ 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 name
|
| 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
|
| 126 |
history_items = data.get("history_items", [])
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
"
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
elif event_type == "taskTagUpdated":
|
| 150 |
history_items = data.get("history_items", [])
|
|
|
|
| 117 |
event_type = data.get("event")
|
| 118 |
task_id = data.get("task_id", "Unknown ID")
|
| 119 |
|
| 120 |
+
# Get task name
|
| 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": # Process only status changes
|
| 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 # Skip if there's no status in 'after'
|
| 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 |
+
|
| 139 |
+
logging.info(f"Task: {task_name}, New Status: {after_status}, Action Date: {action_date_human}")
|
| 140 |
+
|
| 141 |
+
if after_status.lower() == "ready for review":
|
| 142 |
+
whatsapp_payload = {
|
| 143 |
+
"chatId": "201092003112@c.us",
|
| 144 |
+
"message": f"📝 *Task Submitted for Review!*\n\n📌 *Task:* {task_name}\n📅 *Submitted On:* {action_date_human}\n\n🔗 *View Task:* {task_link}\n\nPlease review the task and provide feedback."
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
try:
|
| 148 |
+
whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
|
| 149 |
+
whatsapp_response.raise_for_status()
|
| 150 |
+
logging.info(f"WhatsApp API Response: {whatsapp_response.status_code} - {whatsapp_response.text}")
|
| 151 |
+
except requests.RequestException as e:
|
| 152 |
+
logging.error(f"Failed to send WhatsApp notification: {e}")
|
| 153 |
|
| 154 |
elif event_type == "taskTagUpdated":
|
| 155 |
history_items = data.get("history_items", [])
|