Update app.py
Browse files
app.py
CHANGED
|
@@ -167,79 +167,36 @@ async def create_task(request: Request):
|
|
| 167 |
print("📥 Field Update Response:", field_update.text)
|
| 168 |
|
| 169 |
if task_type_lower in template_ids:
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
for assignee_id in assignee_ids:
|
| 201 |
-
params = {
|
| 202 |
-
"mode": "notify-assigned",
|
| 203 |
-
"assigneeId": assignee_id,
|
| 204 |
-
"spaceId": space_id
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
notify_response = requests.get(web_app_url, params=params)
|
| 208 |
-
if notify_response.ok:
|
| 209 |
-
phone = notify_response.json().get("phone")
|
| 210 |
-
if phone and phone != "not-found":
|
| 211 |
-
chat_id = f"{phone}@c.us"
|
| 212 |
-
task_url = f"https://app.clickup.com/t/{new_task_id}"
|
| 213 |
-
task_name = task_title
|
| 214 |
-
due_timestamp = task_details.get("due_date")
|
| 215 |
-
|
| 216 |
-
if due_timestamp:
|
| 217 |
-
due_str = datetime.utcfromtimestamp(int(due_timestamp) / 1000).strftime('%Y-%m-%d')
|
| 218 |
-
msg = (
|
| 219 |
-
f"📌 *تم تعيين مهمة جديدة لك!*\n\n"
|
| 220 |
-
f"📝 *اسم المهمة:* {task_name}\n"
|
| 221 |
-
f"📅 *تاريخ التسليم:* {due_str}\n"
|
| 222 |
-
f"🔗 *رابط المهمة:* {task_url}"
|
| 223 |
-
)
|
| 224 |
-
else:
|
| 225 |
-
msg = (
|
| 226 |
-
f"📌 *تم تعيين مهمة جديدة لك!*\n\n"
|
| 227 |
-
f"📝 *اسم المهمة:* {task_name}\n"
|
| 228 |
-
f"🔗 *رابط المهمة:* {task_url}"
|
| 229 |
-
)
|
| 230 |
-
|
| 231 |
-
send_whatsapp_notification(chat_id, msg)
|
| 232 |
-
else:
|
| 233 |
-
logging.warning(f"❌ Couldn't fetch phone number for assignee {assignee_id}")
|
| 234 |
-
|
| 235 |
-
return {
|
| 236 |
-
"status": "Template-based task created",
|
| 237 |
-
"task_id": new_task_id
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
else:
|
| 241 |
-
print("❌ Failed to create task from template")
|
| 242 |
-
return {"error": "Template task creation failed"}
|
| 243 |
|
| 244 |
|
| 245 |
# If not using template, fallback to normal creation
|
|
|
|
| 167 |
print("📥 Field Update Response:", field_update.text)
|
| 168 |
|
| 169 |
if task_type_lower in template_ids:
|
| 170 |
+
# Create from template
|
| 171 |
+
template_id = template_ids[task_type_lower]
|
| 172 |
+
template_url = f"{CLICKUP_URL_BASE}/list/{list_id}/taskTemplate/{template_id}"
|
| 173 |
+
template_payload = {
|
| 174 |
+
"name": task_title
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
response = requests.post(template_url, headers=headers, json=template_payload)
|
| 178 |
+
print("Template Creation Status:", response.status_code)
|
| 179 |
+
|
| 180 |
+
if response.ok:
|
| 181 |
+
new_task = response.json()
|
| 182 |
+
new_task_id = new_task.get("id")
|
| 183 |
+
print("✅ Task created from template:", new_task_id)
|
| 184 |
+
|
| 185 |
+
# Update custom field (used as description)
|
| 186 |
+
update_field_url = f"{CLICKUP_URL_BASE}/task/{new_task_id}/field/{custom_field_id}?custom_task_ids=true&team_id={team_id}"
|
| 187 |
+
field_payload = {"value": description_text}
|
| 188 |
+
field_update = requests.post(update_field_url, headers=headers, json=field_payload)
|
| 189 |
+
|
| 190 |
+
print("📥 Field Update Status:", field_update.status_code)
|
| 191 |
+
print("📥 Field Update Response:", field_update.text)
|
| 192 |
+
|
| 193 |
+
return {
|
| 194 |
+
"status": "Template-based task created",
|
| 195 |
+
"task_id": new_task_id
|
| 196 |
+
}
|
| 197 |
+
else:
|
| 198 |
+
print("❌ Failed to create task from template")
|
| 199 |
+
return {"error": "Template task creation failed"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
|
| 202 |
# If not using template, fallback to normal creation
|