Update app.py
Browse files
app.py
CHANGED
|
@@ -104,33 +104,82 @@ async def create_task(request: Request):
|
|
| 104 |
print(f"Assignee Numbers: {assignee_numbers}")
|
| 105 |
print(f"Manager Numbers: {manager_numbers}")
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
status = "to do"
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
if
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
# WhatsApp notification part is commented out for now
|
| 136 |
# We'll handle WhatsApp notification later
|
|
|
|
| 104 |
print(f"Assignee Numbers: {assignee_numbers}")
|
| 105 |
print(f"Manager Numbers: {manager_numbers}")
|
| 106 |
|
| 107 |
+
# Create ClickUp task according to task type
|
| 108 |
+
description_text = ""
|
| 109 |
+
|
| 110 |
+
task_type_lower = task_type.lower()
|
| 111 |
+
|
| 112 |
+
if task_type_lower == "strategy":
|
| 113 |
+
status = "to do"
|
| 114 |
+
description_text = description
|
| 115 |
+
|
| 116 |
+
elif task_type_lower == "content":
|
| 117 |
+
status = "backlog"
|
| 118 |
+
description_text = f"{goal.strip()}".strip()
|
| 119 |
+
if platforms:
|
| 120 |
+
description_text += "\n\nPlatforms: " + ", ".join(platforms)
|
| 121 |
+
|
| 122 |
+
elif task_type_lower == "creative":
|
| 123 |
status = "to do"
|
| 124 |
+
description_text = f"{creative_type.strip()}".strip()
|
| 125 |
+
if platforms:
|
| 126 |
+
description_text += "\n\nPlatforms: " + ", ".join(platforms)
|
| 127 |
+
|
| 128 |
+
elif task_type_lower == "ads":
|
| 129 |
+
status = "ready"
|
| 130 |
+
parts = []
|
| 131 |
+
if ad_content:
|
| 132 |
+
parts.append(ad_content.strip())
|
| 133 |
+
if attachment_link:
|
| 134 |
+
parts.append(f"Attachment: {attachment_link.strip()}")
|
| 135 |
+
if platforms:
|
| 136 |
+
parts.append("Platforms: " + ", ".join(platforms))
|
| 137 |
+
description_text = "\n\n".join(parts)
|
| 138 |
+
|
| 139 |
+
elif task_type_lower == "posting":
|
| 140 |
+
status = "ready for posting"
|
| 141 |
+
parts = []
|
| 142 |
+
if posting_content:
|
| 143 |
+
parts.append(posting_content.strip())
|
| 144 |
+
if platforms:
|
| 145 |
+
parts.append("Platforms: " + ", ".join(platforms))
|
| 146 |
+
if attachment_link:
|
| 147 |
+
parts.append(f"Attachment: {attachment_link.strip()}")
|
| 148 |
+
description_text = "\n\n".join(parts)
|
| 149 |
+
|
| 150 |
+
elif task_type_lower == "ads report":
|
| 151 |
+
status = "ready"
|
| 152 |
+
platforms_text = ", ".join(platforms) if platforms else ""
|
| 153 |
+
description_text = f"Prepare an ads report for {platforms_text}"
|
| 154 |
+
if start_date and end_date:
|
| 155 |
+
description_text += f" from {start_date} to {end_date}"
|
| 156 |
+
|
| 157 |
+
else:
|
| 158 |
+
return {"error": f"Unsupported task type: {task_type}"}
|
| 159 |
+
|
| 160 |
+
# Construct ClickUp task payload
|
| 161 |
+
payload = {
|
| 162 |
+
"name": task_title,
|
| 163 |
+
"description": description_text,
|
| 164 |
+
"assignees": [int(uid) for uid in assignee_ids],
|
| 165 |
+
"status": status
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
# Handle due date
|
| 169 |
+
if deadline:
|
| 170 |
+
try:
|
| 171 |
+
due_timestamp = int(datetime.strptime(deadline, "%Y-%m-%d").timestamp() * 1000)
|
| 172 |
+
payload["due_date"] = due_timestamp
|
| 173 |
+
print(f"Due Date (timestamp): {due_timestamp}")
|
| 174 |
+
except ValueError:
|
| 175 |
+
print("Invalid deadline format. Skipping due_date.")
|
| 176 |
+
|
| 177 |
+
# Send request to ClickUp
|
| 178 |
+
create_url = f"{CLICKUP_URL_BASE}/list/{list_id}/task"
|
| 179 |
+
clickup_response = requests.post(create_url, headers=headers, json=payload)
|
| 180 |
+
clickup_data = clickup_response.json()
|
| 181 |
+
print(f"ClickUp Response: {clickup_response.status_code}, {clickup_data}")
|
| 182 |
+
|
| 183 |
|
| 184 |
# WhatsApp notification part is commented out for now
|
| 185 |
# We'll handle WhatsApp notification later
|