Update app.py
Browse files
app.py
CHANGED
|
@@ -39,4 +39,26 @@ def create_task(task: TaskData):
|
|
| 39 |
}
|
| 40 |
|
| 41 |
response = requests.post(URL, headers=headers, json=payload)
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
response = requests.post(URL, headers=headers, json=payload)
|
| 42 |
+
# Prepare WhatsApp notification
|
| 43 |
+
if response.status_code == 200:
|
| 44 |
+
task_id = response_data.get("id", "Unknown ID")
|
| 45 |
+
task_link = f"https://app.clickup.com/t/{task_id}"
|
| 46 |
+
|
| 47 |
+
whatsapp_payload = {
|
| 48 |
+
"chatId": "201040516950@c.us",
|
| 49 |
+
"message": f"🚀 *New Task Assigned!*\n\n📌 *Task:* {task.task_name}\n📅 *Due Date:* {task.due_date}\n👤 *Assigned To:* {', '.join(map(str, task.assignees))}\n📝 *Description:* {description}\n\n🔗 *View Task:* {task_link}\n\nLet's get this done! ✅"
|
| 50 |
+
}
|
| 51 |
+
else:
|
| 52 |
+
# If ClickUp API fails, send an error message on WhatsApp mentioning the task name
|
| 53 |
+
error_message = response_data.get("err", "Unknown error")
|
| 54 |
+
whatsapp_payload = {
|
| 55 |
+
"chatId": "201040516950@c.us",
|
| 56 |
+
"message": f"⚠️ *Task Creation Failed!*\n\n📌 *Task:* {task.task_name}\n❌ *Error:* {error_message}\n\nPlease check the request and try again."
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
logging.info(f"Sending WhatsApp notification with payload: {whatsapp_payload}")
|
| 60 |
+
whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
|
| 61 |
+
|
| 62 |
+
logging.info(f"WhatsApp API Response: {whatsapp_response.status_code}, {whatsapp_response.json()}")
|
| 63 |
+
|
| 64 |
+
return {"status_code": response.status_code, "response": response_data}
|