Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ WHATSAPP_URL = "https://7105.api.greenapi.com/waInstance7105210836/sendMessage/8
|
|
| 19 |
ACCESS_TOKEN = "2144425825_36f2249dc27c5aca075ac5442b1bbcdf01c3a29b9e41b86bda46a6cf651acd0f"
|
| 20 |
|
| 21 |
# Google Apps Script Data handler
|
| 22 |
-
web_app_url = "https://script.google.com/macros/s/
|
| 23 |
|
| 24 |
# Headers for ClickUp authorization
|
| 25 |
headers = {
|
|
@@ -218,6 +218,46 @@ async def create_task(request: Request):
|
|
| 218 |
clickup_response = requests.post(create_url, headers=headers, json=payload)
|
| 219 |
clickup_data = clickup_response.json()
|
| 220 |
print(f"ClickUp Response: {clickup_response.status_code}, {clickup_data}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
return {"status": "Standard task created", "clickup": clickup_data}
|
| 223 |
|
|
|
|
| 19 |
ACCESS_TOKEN = "2144425825_36f2249dc27c5aca075ac5442b1bbcdf01c3a29b9e41b86bda46a6cf651acd0f"
|
| 20 |
|
| 21 |
# Google Apps Script Data handler
|
| 22 |
+
web_app_url = "https://script.google.com/macros/s/AKfycbx9-oUXV896jM0HbQSz4h61Crf_UYHM8LJMbxXux4PHwf38zqjaJjIJe9O4UyT1u6s/exec"
|
| 23 |
|
| 24 |
# Headers for ClickUp authorization
|
| 25 |
headers = {
|
|
|
|
| 218 |
clickup_response = requests.post(create_url, headers=headers, json=payload)
|
| 219 |
clickup_data = clickup_response.json()
|
| 220 |
print(f"ClickUp Response: {clickup_response.status_code}, {clickup_data}")
|
| 221 |
+
|
| 222 |
+
# After task creation and response
|
| 223 |
+
new_task_id = clickup_data.get("id")
|
| 224 |
+
space_id = clickup_data.get("space", {}).get("id")
|
| 225 |
+
assignee_ids = [str(uid) for uid in assignee_ids] # already known
|
| 226 |
+
|
| 227 |
+
# Notify each assignee
|
| 228 |
+
for assignee_id in assignee_ids:
|
| 229 |
+
params = {
|
| 230 |
+
"mode": "notify-assigned",
|
| 231 |
+
"assigneeId": assignee_id,
|
| 232 |
+
"spaceId": space_id
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
response = requests.get(web_app_url, params=params)
|
| 236 |
+
if response.ok:
|
| 237 |
+
phone = response.json().get("phone")
|
| 238 |
+
if phone and phone != "not-found":
|
| 239 |
+
chat_id = f"{phone}@c.us"
|
| 240 |
+
task_url = f"https://app.clickup.com/t/{new_task_id}"
|
| 241 |
+
task_name = payload["name"]
|
| 242 |
+
due_date = payload.get("due_date")
|
| 243 |
+
if due_date:
|
| 244 |
+
due_str = datetime.utcfromtimestamp(due_date / 1000).strftime('%Y-%m-%d')
|
| 245 |
+
msg = (
|
| 246 |
+
f"📌 *تم تعيين مهمة جديدة لك!*\n\n"
|
| 247 |
+
f"📝 *اسم المهمة:* {task_name}\n"
|
| 248 |
+
f"📅 *تاريخ التسليم:* {due_str}\n"
|
| 249 |
+
f"🔗 *رابط المهمة:* {task_url}"
|
| 250 |
+
)
|
| 251 |
+
else:
|
| 252 |
+
msg = (
|
| 253 |
+
f"📌 *تم تعيين مهمة جديدة لك!*\n\n"
|
| 254 |
+
f"📝 *اسم المهمة:* {task_name}\n"
|
| 255 |
+
f"🔗 *رابط المهمة:* {task_url}"
|
| 256 |
+
)
|
| 257 |
+
send_whatsapp_notification(chat_id, msg)
|
| 258 |
+
else:
|
| 259 |
+
logging.warning(f"❌ Couldn't fetch phone number for assignee {assignee_id}")
|
| 260 |
+
|
| 261 |
|
| 262 |
return {"status": "Standard task created", "clickup": clickup_data}
|
| 263 |
|