Update app.py
Browse files
app.py
CHANGED
|
@@ -39,54 +39,30 @@ class TaskData(BaseModel):
|
|
| 39 |
due_date: int # Unix timestamp in milliseconds
|
| 40 |
|
| 41 |
@app.post("/singetask")
|
| 42 |
-
def create_task(
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
if response.status_code == 200:
|
| 67 |
-
task_id = response_data.get("id", "Unknown ID")
|
| 68 |
-
task_link = f"https://app.clickup.com/t/{task_id}"
|
| 69 |
-
|
| 70 |
-
whatsapp_payload = {
|
| 71 |
-
"chatId": "201092003112@c.us", # Updated recipient number
|
| 72 |
-
"message": f"🚀 *New Task Assigned!*\n\n📌 *Task:* {task.task_name}\n📅 *Due Date:* {due_date_human}\n👤 *Assigned To:* {', '.join(map(str, task.assignees))}\n📝 *Description:* {description}\n\n🔗 *View Task:* {task_link}\n\nLet's get this done! ✅"
|
| 73 |
-
}
|
| 74 |
-
else:
|
| 75 |
-
# If ClickUp API fails, send an error message on WhatsApp mentioning the task name
|
| 76 |
-
error_message = response_data.get("err", "Unknown error")
|
| 77 |
-
failure_time = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
|
| 78 |
-
|
| 79 |
-
whatsapp_payload = {
|
| 80 |
-
"chatId": "201092003112@c.us", # Updated recipient number
|
| 81 |
-
"message": f"⚠️ *Task Creation Failed!*\n\n📌 *Task:* {task.task_name}\n❌ *Error:* {error_message}\n⏰ *Time:* {failure_time}\n\nPlease check the request and try again."
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
logging.info(f"Sending WhatsApp notification with payload: {whatsapp_payload}")
|
| 85 |
-
whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
|
| 86 |
-
|
| 87 |
-
logging.info(f"WhatsApp API Response: {whatsapp_response.status_code}, {whatsapp_response.json()}")
|
| 88 |
-
|
| 89 |
-
return {"status_code": response.status_code, "response": response_data}
|
| 90 |
|
| 91 |
# Function to get task name by task ID
|
| 92 |
def get_task_name(task_id):
|
|
|
|
| 39 |
due_date: int # Unix timestamp in milliseconds
|
| 40 |
|
| 41 |
@app.post("/singetask")
|
| 42 |
+
async def create_task(request: Request):
|
| 43 |
+
data = await request.json()
|
| 44 |
+
logging.info(f"Received task data: {data}")
|
| 45 |
+
|
| 46 |
+
# Extract and assign to variables
|
| 47 |
+
team = data.get('team', '')
|
| 48 |
+
task_type = data.get('taskType', '')
|
| 49 |
+
task_title = data.get('taskTitle', '')
|
| 50 |
+
assignees = data.get('assignees', '')
|
| 51 |
+
platforms = data.get('platforms', [])
|
| 52 |
+
deadline = data.get('deadline', '')
|
| 53 |
+
goal = data.get('goal', '')
|
| 54 |
+
description = data.get('description', '')
|
| 55 |
+
creative_type = data.get('creativeType', '')
|
| 56 |
+
ad_content = data.get('adContent', '')
|
| 57 |
+
posting_content = data.get('postingContent', '')
|
| 58 |
+
attachment_link = data.get('attachmentLink', '')
|
| 59 |
+
start_date = data.get('startDate', '')
|
| 60 |
+
end_date = data.get('endDate', '')
|
| 61 |
+
|
| 62 |
+
# WhatsApp notification part is commented out for now
|
| 63 |
+
# We'll handle WhatsApp notification later
|
| 64 |
+
|
| 65 |
+
return {"status": "Task data received and parsed"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Function to get task name by task ID
|
| 68 |
def get_task_name(task_id):
|