Mr-Help commited on
Commit
63e446c
·
verified ·
1 Parent(s): 56257cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -26
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
- # Strategy task logic
108
- if task_type.lower() == "content":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  status = "to do"
110
- print(f"Status: {status}")
111
-
112
-
113
- # Prepare ClickUp task payload
114
- payload = {
115
- "name": task_title,
116
- "description": description,
117
- "assignees": [int(uid) for uid in assignee_ids],
118
- "status": status
119
- }
120
-
121
- if deadline:
122
- try:
123
- due_timestamp = int(datetime.strptime(deadline, "%Y-%m-%d").timestamp() * 1000)
124
- payload["due_date"] = due_timestamp
125
- print(f"Due Date (timestamp): {due_timestamp}")
126
- except ValueError:
127
- print("Invalid deadline format. Skipping due_date.")
128
-
129
- # Send request to ClickUp
130
- create_url = f"{CLICKUP_URL_BASE}/list/{list_id}/task"
131
- clickup_response = requests.post(create_url, headers=headers, json=payload)
132
- clickup_data = clickup_response.json()
133
- print(f"ClickUp Response: {clickup_response.status_code}, {clickup_data}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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