Mr-Help commited on
Commit
d0435d0
·
verified ·
1 Parent(s): c0da355

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -96,13 +96,22 @@ async def task_update(request: Request):
96
  # Extract necessary fields
97
  task_id = data.get("task_id", "Unknown ID")
98
  task_name = data.get("task", {}).get("name", "Unknown Task")
99
- new_status = data.get("task", {}).get("status", {}).get("status", "").lower()
100
- action_timestamp = data.get("history_items", [{}])[0].get("date", 0) # Get action date if available
101
 
102
- # Convert action timestamp to a human-readable format
 
 
 
 
 
 
 
 
 
103
  action_date_human = datetime.utcfromtimestamp(int(action_timestamp) / 1000).strftime('%Y-%m-%d %H:%M:%S') if action_timestamp else "Unknown Date"
104
 
105
- # If status is "Ready for Review", send a WhatsApp notification
 
 
106
  if new_status == "ready for review":
107
  task_link = f"https://app.clickup.com/t/{task_id}"
108
 
@@ -111,8 +120,12 @@ async def task_update(request: Request):
111
  "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."
112
  }
113
 
114
- logging.info(f"Sending WhatsApp notification for task review: {whatsapp_payload}")
 
 
115
  whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
116
- logging.info(f"WhatsApp API Response: {whatsapp_response.status_code}, {whatsapp_response.json()}")
 
 
117
 
118
  return {"status": "Update received"}
 
96
  # Extract necessary fields
97
  task_id = data.get("task_id", "Unknown ID")
98
  task_name = data.get("task", {}).get("name", "Unknown Task")
 
 
99
 
100
+ # Extract the new status after update
101
+ history_items = data.get("history_items", [])
102
+ if history_items:
103
+ new_status = history_items[0].get("after", {}).get("status", "").lower()
104
+ action_timestamp = history_items[0].get("date", 0)
105
+ else:
106
+ logging.error("No history items found in the update payload.")
107
+ return {"error": "No history items found."}
108
+
109
+ # Convert action timestamp to readable format
110
  action_date_human = datetime.utcfromtimestamp(int(action_timestamp) / 1000).strftime('%Y-%m-%d %H:%M:%S') if action_timestamp else "Unknown Date"
111
 
112
+ logging.info(f"Extracted Status: {new_status}, Task: {task_name}, Date: {action_date_human}")
113
+
114
+ # If status is "Ready for Review", send WhatsApp notification
115
  if new_status == "ready for review":
116
  task_link = f"https://app.clickup.com/t/{task_id}"
117
 
 
120
  "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."
121
  }
122
 
123
+ logging.info(f"Sending WhatsApp notification with payload: {whatsapp_payload}")
124
+
125
+ # Send WhatsApp request
126
  whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
127
+
128
+ logging.info(f"WhatsApp API Response Code: {whatsapp_response.status_code}")
129
+ logging.info(f"WhatsApp API Response: {whatsapp_response.text}")
130
 
131
  return {"status": "Update received"}