Update app.py
Browse files
app.py
CHANGED
|
@@ -191,9 +191,42 @@ async def create_task(request: Request):
|
|
| 191 |
print("📥 Field Update Status:", field_update.status_code)
|
| 192 |
print("📥 Field Update Response:", field_update.text)
|
| 193 |
|
| 194 |
-
# ✅
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
return {
|
| 198 |
"status": "Template-based task created",
|
| 199 |
"task_id": new_task_id
|
|
@@ -286,6 +319,7 @@ async def create_task(request: Request):
|
|
| 286 |
f"🔗 *رابط المهمة:* {task_url}"
|
| 287 |
)
|
| 288 |
send_whatsapp_notification(chat_id, msg)
|
|
|
|
| 289 |
|
| 290 |
else:
|
| 291 |
logging.warning(f"❌ Couldn't fetch phone number for assignee {assignee_id}")
|
|
@@ -293,7 +327,7 @@ async def create_task(request: Request):
|
|
| 293 |
else:
|
| 294 |
return {"error": f"Unsupported task type: {task_type}"}
|
| 295 |
|
| 296 |
-
|
| 297 |
|
| 298 |
# Function to get task name by task ID
|
| 299 |
def get_task_name(task_id):
|
|
|
|
| 191 |
print("📥 Field Update Status:", field_update.status_code)
|
| 192 |
print("📥 Field Update Response:", field_update.text)
|
| 193 |
|
| 194 |
+
# ✅ Notify each assignee (same logic used in standard tasks)
|
| 195 |
+
for assignee_id in assignee_ids:
|
| 196 |
+
params = {
|
| 197 |
+
"mode": "notify-assigned",
|
| 198 |
+
"assigneeId": assignee_id,
|
| 199 |
+
"spaceId": list_id # or fetch space_id if needed
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
response = requests.get(web_app_url, params=params)
|
| 203 |
+
print(f"Assignee to notify {response.json()}")
|
| 204 |
+
if response.ok:
|
| 205 |
+
phone = response.json().get("phone")
|
| 206 |
+
if phone and phone != "not-found":
|
| 207 |
+
chat_id = f"{phone}@c.us"
|
| 208 |
+
task_url = f"https://app.clickup.com/t/{new_task_id}"
|
| 209 |
+
task_name = task_title
|
| 210 |
+
if deadline:
|
| 211 |
+
due_str = datetime.utcfromtimestamp(due_timestamp / 1000).strftime('%Y-%m-%d')
|
| 212 |
+
msg = (
|
| 213 |
+
f"📌 *تم تعيين مهمة جديدة لك!*\n\n"
|
| 214 |
+
f"📝 *اسم المهمة:* {task_name}\n"
|
| 215 |
+
f"📅 *تاريخ التسليم:* {due_str}\n"
|
| 216 |
+
f"🔗 *رابط المهمة:* {task_url}"
|
| 217 |
+
)
|
| 218 |
+
else:
|
| 219 |
+
msg = (
|
| 220 |
+
f"📌 *تم تعيين مهمة جديدة لك!*\n\n"
|
| 221 |
+
f"📝 *اسم المهمة:* {task_name}\n"
|
| 222 |
+
f"🔗 *رابط المهمة:* {task_url}"
|
| 223 |
+
)
|
| 224 |
+
send_whatsapp_notification(chat_id, msg)
|
| 225 |
+
else:
|
| 226 |
+
logging.warning(f"❌ Couldn't fetch phone number for assignee {assignee_id}")
|
| 227 |
+
|
| 228 |
+
# ✅ Then return the response
|
| 229 |
+
|
| 230 |
return {
|
| 231 |
"status": "Template-based task created",
|
| 232 |
"task_id": new_task_id
|
|
|
|
| 319 |
f"🔗 *رابط المهمة:* {task_url}"
|
| 320 |
)
|
| 321 |
send_whatsapp_notification(chat_id, msg)
|
| 322 |
+
return {"status": "Standard task created", "clickup": clickup_data}
|
| 323 |
|
| 324 |
else:
|
| 325 |
logging.warning(f"❌ Couldn't fetch phone number for assignee {assignee_id}")
|
|
|
|
| 327 |
else:
|
| 328 |
return {"error": f"Unsupported task type: {task_type}"}
|
| 329 |
|
| 330 |
+
|
| 331 |
|
| 332 |
# Function to get task name by task ID
|
| 333 |
def get_task_name(task_id):
|