Update app.py
Browse files
app.py
CHANGED
|
@@ -143,61 +143,39 @@ async def create_task(request: Request):
|
|
| 143 |
description_text = "\n\n".join(parts)
|
| 144 |
|
| 145 |
if task_type_lower in template_ids:
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
# Update custom field (used as description)
|
| 162 |
-
update_field_url = f"{CLICKUP_URL_BASE}/task/{new_task_id}/field/{custom_field_id}?custom_task_ids=true&team_id={team_id}"
|
| 163 |
-
field_payload = {"value": description_text}
|
| 164 |
-
field_update = requests.post(update_field_url, headers=headers, json=field_payload)
|
| 165 |
-
|
| 166 |
-
print("📥 Field Update Status:", field_update.status_code)
|
| 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
|
| 203 |
elif task_type_lower in ["strategy", "posting", "ads report"]:
|
|
|
|
| 143 |
description_text = "\n\n".join(parts)
|
| 144 |
|
| 145 |
if task_type_lower in template_ids:
|
| 146 |
+
# Create from template
|
| 147 |
+
template_id = template_ids[task_type_lower]
|
| 148 |
+
template_url = f"{CLICKUP_URL_BASE}/list/{list_id}/taskTemplate/{template_id}"
|
| 149 |
+
template_payload = {
|
| 150 |
+
"name": task_title
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
response = requests.post(template_url, headers=headers, json=template_payload)
|
| 154 |
+
print("Template Creation Status:", response.status_code)
|
| 155 |
+
|
| 156 |
+
if response.ok:
|
| 157 |
+
new_task = response.json()
|
| 158 |
+
new_task_id = new_task.get("id")
|
| 159 |
+
print("✅ Task created from template:", new_task_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
+
# Update custom field (used as description)
|
| 162 |
+
update_field_url = f"{CLICKUP_URL_BASE}/task/{new_task_id}/field/{custom_field_id}?custom_task_ids=true&team_id={team_id}"
|
| 163 |
+
field_payload = {"value": description_text}
|
| 164 |
+
field_update = requests.post(update_field_url, headers=headers, json=field_payload)
|
| 165 |
+
|
| 166 |
+
print("📥 Field Update Status:", field_update.status_code)
|
| 167 |
+
print("📥 Field Update Response:", field_update.text)
|
| 168 |
+
|
| 169 |
+
# ✅ Add WhatsApp notification logic here (already done earlier)
|
| 170 |
+
# ...
|
| 171 |
+
|
| 172 |
+
return {
|
| 173 |
+
"status": "Template-based task created",
|
| 174 |
+
"task_id": new_task_id
|
| 175 |
+
}
|
| 176 |
+
else:
|
| 177 |
+
print("❌ Failed to create task from template")
|
| 178 |
+
return {"error": "Template task creation failed"}
|
| 179 |
|
| 180 |
# If not using template, fallback to normal creation
|
| 181 |
elif task_type_lower in ["strategy", "posting", "ads report"]:
|