Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
-
# ClickUp API URL for creating a task
|
| 8 |
LIST_ID = "901208781277"
|
| 9 |
URL = f"https://api.clickup.com/api/v2/list/{LIST_ID}/task"
|
| 10 |
|
|
@@ -14,12 +18,17 @@ WHATSAPP_URL = "https://7105.api.greenapi.com/waInstance7105210836/sendMessage/8
|
|
| 14 |
# Your access token
|
| 15 |
ACCESS_TOKEN = "2144425825_36f2249dc27c5aca075ac5442b1bbcdf01c3a29b9e41b86bda46a6cf651acd0f"
|
| 16 |
|
| 17 |
-
# Headers for authorization
|
| 18 |
headers = {
|
| 19 |
"Authorization": ACCESS_TOKEN,
|
| 20 |
"Content-Type": "application/json"
|
| 21 |
}
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
class TaskData(BaseModel):
|
| 24 |
task_name: str
|
| 25 |
task_type: str # "Reel" or "Design"
|
|
@@ -30,6 +39,8 @@ class TaskData(BaseModel):
|
|
| 30 |
|
| 31 |
@app.post("/singetask")
|
| 32 |
def create_task(task: TaskData):
|
|
|
|
|
|
|
| 33 |
description = f"Task Type: {task.task_type}\nCampaign: {task.campaign_name}\nPlatforms: {', '.join(task.platforms)}"
|
| 34 |
|
| 35 |
payload = {
|
|
@@ -40,12 +51,13 @@ def create_task(task: TaskData):
|
|
| 40 |
"due_date": task.due_date, # Unix timestamp in milliseconds
|
| 41 |
"status": "backlog" # Adjust based on your workflow
|
| 42 |
}
|
| 43 |
-
|
|
|
|
| 44 |
response = requests.post(URL, headers=headers, json=payload)
|
| 45 |
-
|
| 46 |
-
response_data = response.json()
|
| 47 |
-
print(f"Received response from ClickUp: {response.status_code}, {response_data}")
|
| 48 |
|
|
|
|
|
|
|
|
|
|
| 49 |
# Prepare WhatsApp notification
|
| 50 |
if response.status_code == 200:
|
| 51 |
task_id = response_data.get("id", "Unknown ID")
|
|
@@ -63,9 +75,9 @@ def create_task(task: TaskData):
|
|
| 63 |
"message": f"⚠️ *Task Creation Failed!*\n\n📌 *Task:* {task.task_name}\n❌ *Error:* {error_message}\n\nPlease check the request and try again."
|
| 64 |
}
|
| 65 |
|
| 66 |
-
|
| 67 |
whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
|
| 68 |
|
| 69 |
-
|
| 70 |
|
| 71 |
-
return {"status_code": response.status_code, "response": response_data}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import requests
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
# Configure logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
+
# ClickUp API URL for creating a task
|
| 12 |
LIST_ID = "901208781277"
|
| 13 |
URL = f"https://api.clickup.com/api/v2/list/{LIST_ID}/task"
|
| 14 |
|
|
|
|
| 18 |
# Your access token
|
| 19 |
ACCESS_TOKEN = "2144425825_36f2249dc27c5aca075ac5442b1bbcdf01c3a29b9e41b86bda46a6cf651acd0f"
|
| 20 |
|
| 21 |
+
# Headers for ClickUp authorization
|
| 22 |
headers = {
|
| 23 |
"Authorization": ACCESS_TOKEN,
|
| 24 |
"Content-Type": "application/json"
|
| 25 |
}
|
| 26 |
|
| 27 |
+
# Headers for WhatsApp API
|
| 28 |
+
whatsapp_headers = {
|
| 29 |
+
"Content-Type": "application/json"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
class TaskData(BaseModel):
|
| 33 |
task_name: str
|
| 34 |
task_type: str # "Reel" or "Design"
|
|
|
|
| 39 |
|
| 40 |
@app.post("/singetask")
|
| 41 |
def create_task(task: TaskData):
|
| 42 |
+
logging.info(f"Received task data: {task}")
|
| 43 |
+
|
| 44 |
description = f"Task Type: {task.task_type}\nCampaign: {task.campaign_name}\nPlatforms: {', '.join(task.platforms)}"
|
| 45 |
|
| 46 |
payload = {
|
|
|
|
| 51 |
"due_date": task.due_date, # Unix timestamp in milliseconds
|
| 52 |
"status": "backlog" # Adjust based on your workflow
|
| 53 |
}
|
| 54 |
+
|
| 55 |
+
logging.info(f"Sending request to ClickUp with payload: {payload}")
|
| 56 |
response = requests.post(URL, headers=headers, json=payload)
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
response_data = response.json()
|
| 59 |
+
logging.info(f"Received response from ClickUp: {response.status_code}, {response_data}")
|
| 60 |
+
|
| 61 |
# Prepare WhatsApp notification
|
| 62 |
if response.status_code == 200:
|
| 63 |
task_id = response_data.get("id", "Unknown ID")
|
|
|
|
| 75 |
"message": f"⚠️ *Task Creation Failed!*\n\n📌 *Task:* {task.task_name}\n❌ *Error:* {error_message}\n\nPlease check the request and try again."
|
| 76 |
}
|
| 77 |
|
| 78 |
+
logging.info(f"Sending WhatsApp notification with payload: {whatsapp_payload}")
|
| 79 |
whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
|
| 80 |
|
| 81 |
+
logging.info(f"WhatsApp API Response: {whatsapp_response.status_code}, {whatsapp_response.json()}")
|
| 82 |
|
| 83 |
+
return {"status_code": response.status_code, "response": response_data}
|