Update app.py
Browse files
app.py
CHANGED
|
@@ -299,9 +299,27 @@ async def task_update(request: Request):
|
|
| 299 |
"mode": "notify",
|
| 300 |
"spaceId": space_id,
|
| 301 |
}
|
|
|
|
| 302 |
# Append assignees[] multiple times for each ID
|
| 303 |
for assignee_id in assignee_ids:
|
| 304 |
params.setdefault("assignees", []).append(assignee_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
# Step 3: Make the request
|
| 307 |
response = requests.get(web_app_url, params=params)
|
|
@@ -316,35 +334,39 @@ async def task_update(request: Request):
|
|
| 316 |
manager_numbers = notify_map.get("managers", [])
|
| 317 |
|
| 318 |
print("📞 User Numbers:", user_numbers)
|
| 319 |
-
print("👨💼 Manager Numbers:", manager_numbers
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
|
|
|
|
|
|
|
|
|
| 326 |
|
| 327 |
-
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
| 333 |
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
logging.info(f"Missed Due Date Tag Added for Task: {task_name}, Due Date: {due_date}")
|
| 339 |
|
| 340 |
-
chat_id = "201092003112@c.us"
|
| 341 |
-
message = (
|
| 342 |
-
f"⚠️ *Task Missed Due Date!*\n\n"
|
| 343 |
-
f"📌 *Task:* {task_name}\n"
|
| 344 |
-
f"📅 *Due Date:* {due_date}\n\n"
|
| 345 |
-
f"🔗 *View Task:* {task_link}\n\n"
|
| 346 |
-
f"Please take action immediately."
|
| 347 |
-
)
|
| 348 |
-
send_whatsapp_notification(chat_id, message)
|
| 349 |
-
|
| 350 |
return {"status": "Update received"}
|
|
|
|
| 299 |
"mode": "notify",
|
| 300 |
"spaceId": space_id,
|
| 301 |
}
|
| 302 |
+
|
| 303 |
# Append assignees[] multiple times for each ID
|
| 304 |
for assignee_id in assignee_ids:
|
| 305 |
params.setdefault("assignees", []).append(assignee_id)
|
| 306 |
+
|
| 307 |
+
# ✅ Get task name
|
| 308 |
+
task_name = task_details.get("name", "Unnamed Task")
|
| 309 |
+
|
| 310 |
+
# ✅ Get assignee names
|
| 311 |
+
assignee_names = [assignee.get("username") for assignee in task_details.get("assignees", [])]
|
| 312 |
+
|
| 313 |
+
# ✅ Print the values
|
| 314 |
+
print("📝 Task Name:", task_name)
|
| 315 |
+
print("👥 Assignees:", assignee_names)
|
| 316 |
+
|
| 317 |
+
task_url = task_details.get("url", "")
|
| 318 |
+
print("🔗 Task URL:", task_url)
|
| 319 |
+
|
| 320 |
+
# Get due date
|
| 321 |
+
due_date_timestamp = task_details.get("due_date")
|
| 322 |
+
due_date = datetime.utcfromtimestamp(int(due_date_timestamp) / 1000).strftime('%Y-%m-%d') if due_date_timestamp else "Unknown Due Date"
|
| 323 |
|
| 324 |
# Step 3: Make the request
|
| 325 |
response = requests.get(web_app_url, params=params)
|
|
|
|
| 334 |
manager_numbers = notify_map.get("managers", [])
|
| 335 |
|
| 336 |
print("📞 User Numbers:", user_numbers)
|
| 337 |
+
print("👨💼 Manager Numbers:", manager_numbers
|
| 338 |
+
|
| 339 |
+
# ✅ Arabic WhatsApp messages
|
| 340 |
+
user_message = (
|
| 341 |
+
f"⚠️ *تنبيه بتأخر المهمة!*\n\n"
|
| 342 |
+
f"📌 *المهمة:* {task_name}\n"
|
| 343 |
+
f"📅 *تاريخ التسليم:* {due_date}\n"
|
| 344 |
+
f"🔗 *رابط المهمة:* {task_url}\n\n"
|
| 345 |
+
f"يرجى اتخاذ الإجراء اللازم فوراً."
|
| 346 |
+
)
|
| 347 |
|
| 348 |
+
manager_message = (
|
| 349 |
+
f"📣 *تنبيه للمدير:*\n\n"
|
| 350 |
+
f"📌 *الموظف:* {assignee_name_str}\n"
|
| 351 |
+
f"❌ *تأخر في مهمة:* {task_name}\n"
|
| 352 |
+
f"📅 *تاريخ التسليم:* {due_date}\n"
|
| 353 |
+
f"🔗 *رابط المهمة:* {task_url}\n\n"
|
| 354 |
+
f"يرجى المتابعة مع الفريق."
|
| 355 |
+
)
|
| 356 |
|
| 357 |
+
# ✅ Loop and send to users
|
| 358 |
+
for num in user_numbers:
|
| 359 |
+
chat_id = f"{num}@c.us"
|
| 360 |
+
send_whatsapp_notification(chat_id, user_message)
|
| 361 |
|
| 362 |
+
# ✅ Loop and send to managers
|
| 363 |
+
for num in manager_numbers:
|
| 364 |
+
chat_id = f"{num}@c.us"
|
| 365 |
+
send_whatsapp_notification(chat_id, manager_message)
|
| 366 |
+
else:
|
| 367 |
+
print("❌ Failed to fetch notify data:", response.status_code)
|
| 368 |
+
print("Raw response:", response.text)
|
| 369 |
+
|
| 370 |
logging.info(f"Missed Due Date Tag Added for Task: {task_name}, Due Date: {due_date}")
|
| 371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
return {"status": "Update received"}
|