| from fastapi import FastAPI |
| from pydantic import BaseModel |
| import requests |
|
|
| app = FastAPI() |
|
|
| |
| LIST_ID = "901208781277" |
| URL = f"https://api.clickup.com/api/v2/list/{LIST_ID}/task" |
|
|
| |
| ACCESS_TOKEN = "2144425825_36f2249dc27c5aca075ac5442b1bbcdf01c3a29b9e41b86bda46a6cf651acd0f" |
|
|
| |
| headers = { |
| "Authorization": ACCESS_TOKEN, |
| "Content-Type": "application/json" |
| } |
|
|
| class TaskData(BaseModel): |
| task_name: str |
| task_type: str |
| campaign_name: str |
| platforms: list[str] |
| assignees: list[int] |
| due_date: int |
|
|
| @app.post("/singetask") |
| def create_task(task: TaskData): |
| description = f"Task Type: {task.task_type}\nCampaign: {task.campaign_name}\nPlatforms: {', '.join(task.platforms)}" |
| |
| payload = { |
| "name": task.task_name, |
| "description": description, |
| "assignees": task.assignees, |
| "priority": 3, |
| "due_date": task.due_date, |
| "status": "backlog" |
| } |
|
|
| response = requests.post(URL, headers=headers, json=payload) |
|
|
| response_data = response.json() |
| print(f"Received response from ClickUp: {response.status_code}, {response_data}") |
| |
| |
| if response.status_code == 200: |
| task_id = response_data.get("id", "Unknown ID") |
| task_link = f"https://app.clickup.com/t/{task_id}" |
| |
| whatsapp_payload = { |
| "chatId": "201040516950@c.us", |
| "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! ✅" |
| } |
| else: |
| |
| error_message = response_data.get("err", "Unknown error") |
| whatsapp_payload = { |
| "chatId": "201040516950@c.us", |
| "message": f"⚠️ *Task Creation Failed!*\n\n📌 *Task:* {task.task_name}\n❌ *Error:* {error_message}\n\nPlease check the request and try again." |
| } |
|
|
| print(f"Sending WhatsApp notification with payload: {whatsapp_payload}") |
| whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers) |
| |
| print(f"WhatsApp API Response: {whatsapp_response.status_code}, {whatsapp_response.json()}") |
|
|
| return {"status_code": response.status_code, "response": response_data} |