Mr-Help commited on
Commit
e7c30e5
·
verified ·
1 Parent(s): dd83bd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -22
app.py CHANGED
@@ -221,6 +221,18 @@ def get_task_details(task_id):
221
 
222
  return task_data
223
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  @app.post("/updates")
225
  async def task_update(request: Request):
226
  data = await request.json()
@@ -250,17 +262,15 @@ async def task_update(request: Request):
250
  logging.info(f"Task: {task_name}, New Status: {after_status}, Action Date: {action_date_human}")
251
 
252
  if after_status.lower() == "ready for review":
253
- whatsapp_payload = {
254
- "chatId": "201092003112@c.us",
255
- "message": f"📝 *Task Submitted for Review!*\n\n📌 *Task:* {task_name}\n📅 *Submitted On:* {action_date_human}\n\n🔗 *View Task:* {task_link}\n\nPlease review the task and provide feedback."
256
- }
257
-
258
- try:
259
- whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
260
- whatsapp_response.raise_for_status()
261
- logging.info(f"WhatsApp API Response: {whatsapp_response.status_code} - {whatsapp_response.text}")
262
- except requests.RequestException as e:
263
- logging.error(f"Failed to send WhatsApp notification: {e}")
264
 
265
  elif event_type == "taskTagUpdated":
266
  history_items = data.get("history_items", [])
@@ -277,16 +287,14 @@ async def task_update(request: Request):
277
 
278
  logging.info(f"Missed Due Date Tag Added for Task: {task_name}, Due Date: {due_date}")
279
 
280
- whatsapp_payload = {
281
- "chatId": "201092003112@c.us",
282
- "message": f"⚠️ *Task Missed Due Date!*\n\n📌 *Task:* {task_name}\n📅 *Due Date:* {due_date}\n\n🔗 *View Task:* {task_link}\n\nPlease take action immediately."
283
- }
284
-
285
- try:
286
- whatsapp_response = requests.post(WHATSAPP_URL, json=whatsapp_payload, headers=whatsapp_headers)
287
- whatsapp_response.raise_for_status()
288
- logging.info(f"WhatsApp API Response: {whatsapp_response.status_code} - {whatsapp_response.text}")
289
- except requests.RequestException as e:
290
- logging.error(f"Failed to send WhatsApp notification: {e}")
291
 
292
  return {"status": "Update received"}
 
221
 
222
  return task_data
223
 
224
+ def send_whatsapp_notification(chat_id: str, message: str):
225
+ payload = {
226
+ "chatId": chat_id,
227
+ "message": message
228
+ }
229
+ try:
230
+ response = requests.post(WHATSAPP_URL, json=payload, headers=whatsapp_headers)
231
+ response.raise_for_status()
232
+ logging.info(f"WhatsApp sent to {chat_id} - {response.status_code}: {response.text}")
233
+ except requests.RequestException as e:
234
+ logging.error(f"WhatsApp send failed for {chat_id}: {e}")
235
+
236
  @app.post("/updates")
237
  async def task_update(request: Request):
238
  data = await request.json()
 
262
  logging.info(f"Task: {task_name}, New Status: {after_status}, Action Date: {action_date_human}")
263
 
264
  if after_status.lower() == "ready for review":
265
+ chat_id = "201092003112@c.us"
266
+ message = (
267
+ f"📝 *Task Submitted for Review!*\n\n"
268
+ f"📌 *Task:* {task_name}\n"
269
+ f"📅 *Submitted On:* {action_date_human}\n\n"
270
+ f"🔗 *View Task:* {task_link}\n\n"
271
+ f"Please review the task and provide feedback."
272
+ )
273
+ send_whatsapp_notification(chat_id, message)
 
 
274
 
275
  elif event_type == "taskTagUpdated":
276
  history_items = data.get("history_items", [])
 
287
 
288
  logging.info(f"Missed Due Date Tag Added for Task: {task_name}, Due Date: {due_date}")
289
 
290
+ chat_id = "201092003112@c.us"
291
+ message = (
292
+ f"⚠️ *Task Missed Due Date!*\n\n"
293
+ f"📌 *Task:* {task_name}\n"
294
+ f"📅 *Due Date:* {due_date}\n\n"
295
+ f"🔗 *View Task:* {task_link}\n\n"
296
+ f"Please take action immediately."
297
+ )
298
+ send_whatsapp_notification(chat_id, message)
 
 
299
 
300
  return {"status": "Update received"}