Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ WHATSAPP_URL = "https://7105.api.greenapi.com/waInstance7105210836/sendMessage/8
|
|
| 19 |
ACCESS_TOKEN = "2144425825_36f2249dc27c5aca075ac5442b1bbcdf01c3a29b9e41b86bda46a6cf651acd0f"
|
| 20 |
|
| 21 |
# Google Apps Script Data handler
|
| 22 |
-
web_app_url = "https://script.google.com/macros/s/
|
| 23 |
|
| 24 |
# Headers for ClickUp authorization
|
| 25 |
headers = {
|
|
@@ -263,15 +263,78 @@ async def task_update(request: Request):
|
|
| 263 |
logging.info(f"Task: {task_name}, New Status: {after_status}, Action Date: {action_date_human}")
|
| 264 |
|
| 265 |
if after_status.lower() == "ready for review":
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
)
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
elif event_type == "taskTagUpdated":
|
| 277 |
history_items = data.get("history_items", [])
|
|
|
|
| 19 |
ACCESS_TOKEN = "2144425825_36f2249dc27c5aca075ac5442b1bbcdf01c3a29b9e41b86bda46a6cf651acd0f"
|
| 20 |
|
| 21 |
# Google Apps Script Data handler
|
| 22 |
+
web_app_url = "https://script.google.com/macros/s/AKfycbxuN5YtKgFkXu1gu-dafyDHz0JII0F2RLifhVi8YVclabenlPt0X3780ChQHRdE_Ccc/exec"
|
| 23 |
|
| 24 |
# Headers for ClickUp authorization
|
| 25 |
headers = {
|
|
|
|
| 263 |
logging.info(f"Task: {task_name}, New Status: {after_status}, Action Date: {action_date_human}")
|
| 264 |
|
| 265 |
if after_status.lower() == "ready for review":
|
| 266 |
+
# Step 1: Get task details
|
| 267 |
+
task_details = get_task_details(task_id)
|
| 268 |
+
print(f"Task details: {task_details}")
|
| 269 |
+
|
| 270 |
+
task_name = task_details.get("name", "Unnamed Task")
|
| 271 |
+
task_url = task_details.get("url", "")
|
| 272 |
+
space_id = task_details.get("space", {}).get("id")
|
| 273 |
+
assignees = task_details.get("assignees", [])
|
| 274 |
+
assignee_ids = [str(assignee['id']) for assignee in assignees]
|
| 275 |
+
assignee_id_to_name = {str(assignee['id']): assignee['username'] for assignee in assignees}
|
| 276 |
+
assignee_names_str = "، ".join(assignee_id_to_name.values())
|
| 277 |
+
|
| 278 |
+
# Step 2: Call WebApp for notify-roles
|
| 279 |
+
web_app_url = "https://script.google.com/macros/s/AKfycbxuN5YtKgFkXu1gu-dafyDHz0JII0F2RLifhVi8YVclabenlPt0X3780ChQHRdE_Ccc/exec"
|
| 280 |
+
params = {
|
| 281 |
+
"mode": "notify-roles",
|
| 282 |
+
"assigneeId": assignee_ids[0], # Assume main assignee
|
| 283 |
+
"spaceId": space_id
|
| 284 |
+
}
|
| 285 |
+
response = requests.get(web_app_url, params=params)
|
| 286 |
+
|
| 287 |
+
if response.ok:
|
| 288 |
+
notify_map = response.json()
|
| 289 |
+
print("✅ Notify Map:", notify_map)
|
| 290 |
+
|
| 291 |
+
# 1️⃣ Notify the user (confirmation)
|
| 292 |
+
user_dict = notify_map.get("users", {})
|
| 293 |
+
for user_id, number in user_dict.items():
|
| 294 |
+
chat_id = f"{number}@c.us"
|
| 295 |
+
user_message = (
|
| 296 |
+
f"✅ *تم نقل المهمة للمراجعة بنجاح!*\n\n"
|
| 297 |
+
f"📌 *المهمة:* {task_name}\n"
|
| 298 |
+
f"📅 *التاريخ:* {action_date_human}\n"
|
| 299 |
+
f"🔗 *رابط المهمة:* {task_url}\n\n"
|
| 300 |
+
f"شكراً لك على استكمال المهمة."
|
| 301 |
+
)
|
| 302 |
+
send_whatsapp_notification(chat_id, user_message)
|
| 303 |
+
|
| 304 |
+
# 2️⃣ Notify the team roles
|
| 305 |
+
notify_users = notify_map.get("notifyUsers", [])
|
| 306 |
+
for user in notify_users:
|
| 307 |
+
name = user.get("name", "عضو الفريق")
|
| 308 |
+
number = user.get("phone")
|
| 309 |
+
if number:
|
| 310 |
+
chat_id = f"{number}@c.us"
|
| 311 |
+
notify_message = (
|
| 312 |
+
f"📣 *تنبيه للفريق:*\n\n"
|
| 313 |
+
f"📌 *{assignee_names_str}* قام بنقل المهمة التالية للمراجعة:\n"
|
| 314 |
+
f"*{task_name}*\n"
|
| 315 |
+
f"🔗 {task_url}\n\n"
|
| 316 |
+
f"يرجى مراجعة المهمة وإضافة ملاحظاتك."
|
| 317 |
+
)
|
| 318 |
+
send_whatsapp_notification(chat_id, notify_message)
|
| 319 |
+
|
| 320 |
+
# 3️⃣ Notify the managers
|
| 321 |
+
managers = notify_map.get("managers", [])
|
| 322 |
+
for manager in managers:
|
| 323 |
+
manager_name = manager.get("name", "مدير")
|
| 324 |
+
number = manager.get("phone")
|
| 325 |
+
if number:
|
| 326 |
+
chat_id = f"{number}@c.us"
|
| 327 |
+
manager_message = (
|
| 328 |
+
f"👤 *إشعار للمدير:*\n\n"
|
| 329 |
+
f"📌 *{assignee_names_str}* قام بنقل المهمة للمراجعة:\n"
|
| 330 |
+
f"*{task_name}*\n"
|
| 331 |
+
f"🔗 {task_url}\n\n"
|
| 332 |
+
f"يمكنك إلقاء نظرة وإضافة ملاحظات إن وجدت."
|
| 333 |
+
)
|
| 334 |
+
send_whatsapp_notification(chat_id, manager_message)
|
| 335 |
+
else:
|
| 336 |
+
logging.error(f"❌ Failed to fetch notify-roles data: {response.status_code}")
|
| 337 |
+
print("Raw response:", response.text)
|
| 338 |
|
| 339 |
elif event_type == "taskTagUpdated":
|
| 340 |
history_items = data.get("history_items", [])
|