Mr-Help commited on
Commit
231c278
·
verified ·
1 Parent(s): 6e19536

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -48
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(task: TaskData):
43
- logging.info(f"Received task data: {task}")
44
-
45
- # Convert Unix timestamp to a readable date
46
- due_date_human = datetime.utcfromtimestamp(task.due_date / 1000).strftime('%Y-%m-%d %H:%M:%S')
47
-
48
- description = f"Task Type: {task.task_type}\nCampaign: {task.campaign_name}\nPlatforms: {', '.join(task.platforms)}"
49
-
50
- payload = {
51
- "name": task.task_name,
52
- "description": description,
53
- "assignees": task.assignees,
54
- "priority": 3, # Priority levels: 1 (Low), 2 (Normal), 3 (High), 4 (Urgent)
55
- "due_date": task.due_date, # Unix timestamp in milliseconds
56
- "status": "backlog" # Adjust based on your workflow
57
- }
58
-
59
- logging.info(f"Sending request to ClickUp with payload: {payload}")
60
- response = requests.post(URL, headers=headers, json=payload)
61
-
62
- response_data = response.json()
63
- logging.info(f"Received response from ClickUp: {response.status_code}, {response_data}")
64
-
65
- # Prepare WhatsApp notification
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):