Mr-Help commited on
Commit
2ce55e1
·
verified ·
1 Parent(s): 14e5b99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -23
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 using the new function
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 the new status
126
  history_items = data.get("history_items", [])
127
- if history_items:
128
- new_status = history_items[0].get("after", {}).get("status", "").lower()
129
- action_timestamp = history_items[0].get("date", 0)
130
- else:
131
- logging.error("No history items found in taskUpdated event.")
132
- return {"error": "No history items found."}
133
-
134
- # Convert action timestamp to readable date
135
- action_date_human = datetime.utcfromtimestamp(int(action_timestamp) / 1000).strftime('%Y-%m-%d %H:%M:%S') if action_timestamp else "Unknown Date"
136
-
137
- logging.info(f"Task: {task_name}, New Status: {new_status}, Action Date: {action_date_human}")
138
-
139
- if new_status == "ready for review":
140
- whatsapp_payload = {
141
- "chatId": "201092003112@c.us",
142
- "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."
143
- }
144
-
145
- logging.info(f"Sending WhatsApp notification: {whatsapp_payload}")
146
- whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
147
- logging.info(f"WhatsApp API Response: {whatsapp_response.status_code} - {whatsapp_response.text}")
 
 
 
 
 
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", [])