Update app.py
Browse files
app.py
CHANGED
|
@@ -221,6 +221,18 @@ def get_task_details(task_id):
|
|
| 221 |
|
| 222 |
return task_data
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
@app.post("/updates")
|
| 225 |
async def task_update(request: Request):
|
| 226 |
data = await request.json()
|
|
@@ -250,17 +262,15 @@ async def task_update(request: Request):
|
|
| 250 |
logging.info(f"Task: {task_name}, New Status: {after_status}, Action Date: {action_date_human}")
|
| 251 |
|
| 252 |
if after_status.lower() == "ready for review":
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
except requests.RequestException as e:
|
| 263 |
-
logging.error(f"Failed to send WhatsApp notification: {e}")
|
| 264 |
|
| 265 |
elif event_type == "taskTagUpdated":
|
| 266 |
history_items = data.get("history_items", [])
|
|
@@ -277,16 +287,14 @@ async def task_update(request: Request):
|
|
| 277 |
|
| 278 |
logging.info(f"Missed Due Date Tag Added for Task: {task_name}, Due Date: {due_date}")
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
except requests.RequestException as e:
|
| 290 |
-
logging.error(f"Failed to send WhatsApp notification: {e}")
|
| 291 |
|
| 292 |
return {"status": "Update received"}
|
|
|
|
| 221 |
|
| 222 |
return task_data
|
| 223 |
|
| 224 |
+
def send_whatsapp_notification(chat_id: str, message: str):
|
| 225 |
+
payload = {
|
| 226 |
+
"chatId": chat_id,
|
| 227 |
+
"message": message
|
| 228 |
+
}
|
| 229 |
+
try:
|
| 230 |
+
response = requests.post(WHATSAPP_URL, json=payload, headers=whatsapp_headers)
|
| 231 |
+
response.raise_for_status()
|
| 232 |
+
logging.info(f"WhatsApp sent to {chat_id} - {response.status_code}: {response.text}")
|
| 233 |
+
except requests.RequestException as e:
|
| 234 |
+
logging.error(f"WhatsApp send failed for {chat_id}: {e}")
|
| 235 |
+
|
| 236 |
@app.post("/updates")
|
| 237 |
async def task_update(request: Request):
|
| 238 |
data = await request.json()
|
|
|
|
| 262 |
logging.info(f"Task: {task_name}, New Status: {after_status}, Action Date: {action_date_human}")
|
| 263 |
|
| 264 |
if after_status.lower() == "ready for review":
|
| 265 |
+
chat_id = "201092003112@c.us"
|
| 266 |
+
message = (
|
| 267 |
+
f"📝 *Task Submitted for Review!*\n\n"
|
| 268 |
+
f"📌 *Task:* {task_name}\n"
|
| 269 |
+
f"📅 *Submitted On:* {action_date_human}\n\n"
|
| 270 |
+
f"🔗 *View Task:* {task_link}\n\n"
|
| 271 |
+
f"Please review the task and provide feedback."
|
| 272 |
+
)
|
| 273 |
+
send_whatsapp_notification(chat_id, message)
|
|
|
|
|
|
|
| 274 |
|
| 275 |
elif event_type == "taskTagUpdated":
|
| 276 |
history_items = data.get("history_items", [])
|
|
|
|
| 287 |
|
| 288 |
logging.info(f"Missed Due Date Tag Added for Task: {task_name}, Due Date: {due_date}")
|
| 289 |
|
| 290 |
+
chat_id = "201092003112@c.us"
|
| 291 |
+
message = (
|
| 292 |
+
f"⚠️ *Task Missed Due Date!*\n\n"
|
| 293 |
+
f"📌 *Task:* {task_name}\n"
|
| 294 |
+
f"📅 *Due Date:* {due_date}\n\n"
|
| 295 |
+
f"🔗 *View Task:* {task_link}\n\n"
|
| 296 |
+
f"Please take action immediately."
|
| 297 |
+
)
|
| 298 |
+
send_whatsapp_notification(chat_id, message)
|
|
|
|
|
|
|
| 299 |
|
| 300 |
return {"status": "Update received"}
|