Mr-Help commited on
Commit
ffed1e6
·
verified ·
1 Parent(s): 41c2196

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -59
app.py CHANGED
@@ -143,70 +143,70 @@ async def create_task(request: Request):
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"]:
182
- if task_type_lower == "strategy":
183
- status = "to do"
184
- description_text = description
185
 
186
- elif task_type_lower == "posting":
187
- status = "ready for posting"
188
- parts = []
189
- if posting_content:
190
- parts.append(posting_content.strip())
191
- if platforms:
192
- parts.append("Platforms: " + ", ".join(platforms))
193
- if attachment_link:
194
- parts.append(f"Attachment: {attachment_link.strip()}")
195
- description_text = "\n\n".join(parts)
196
 
197
- elif task_type_lower == "ads report":
198
- status = "ready"
199
- platforms_text = ", ".join(platforms) if platforms else ""
200
- description_text = f"Prepare an ads report for {platforms_text}"
201
- if start_date and end_date:
202
- description_text += f" from {start_date} to {end_date}"
203
 
204
- payload = {
205
- "name": task_title,
206
- "description": description_text,
207
- "assignees": [int(uid) for uid in assignee_ids],
208
- "status": status
209
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
 
211
  # Handle due date
212
  if deadline:
 
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"]:
182
+ if task_type_lower == "strategy":
183
+ status = "to do"
184
+ description_text = description
185
+
186
+ elif task_type_lower == "posting":
187
+ status = "ready for posting"
188
+ parts = []
189
+ if posting_content:
190
+ parts.append(posting_content.strip())
191
+ if platforms:
192
+ parts.append("Platforms: " + ", ".join(platforms))
193
+ if attachment_link:
194
+ parts.append(f"Attachment: {attachment_link.strip()}")
195
+ description_text = "\n\n".join(parts)
196
+
197
+ elif task_type_lower == "ads report":
198
+ status = "ready"
199
+ platforms_text = ", ".join(platforms) if platforms else ""
200
+ description_text = f"Prepare an ads report for {platforms_text}"
201
+ if start_date and end_date:
202
+ description_text += f" from {start_date} to {end_date}"
203
+
204
+ payload = {
205
+ "name": task_title,
206
+ "description": description_text,
207
+ "assignees": [int(uid) for uid in assignee_ids],
208
+ "status": status
209
+ }
210
 
211
  # Handle due date
212
  if deadline: