From 978f51d8cda340c84fa40ab599c60092b81bcdeb Mon Sep 17 00:00:00 2001 From: Jepp9350 <2jepp9350@gmail.com> Date: Thu, 12 Jun 2025 19:56:59 +0200 Subject: [PATCH] Expand `Limble` module with new webhook payload helpers, JSON validation, Slack notifications, and task-specific webhook handling logic. --- .../limble/helpers/limble_webhook_payload.php | 4 + .../helpers/limble_webhook_payload_task.php | 75 +++++++++++++++++++ .../app/modules/limble/limble_helpers.php | 9 +++ .../nginx/app/routes/moduleLimbleRoute.php | 15 +++- 4 files changed, 101 insertions(+), 2 deletions(-) diff --git a/services/nginx/app/modules/limble/helpers/limble_webhook_payload.php b/services/nginx/app/modules/limble/helpers/limble_webhook_payload.php index c3ab6aff..60545a41 100644 --- a/services/nginx/app/modules/limble/helpers/limble_webhook_payload.php +++ b/services/nginx/app/modules/limble/helpers/limble_webhook_payload.php @@ -2,6 +2,8 @@ namespace limble\helpers; +use classes\slack; + abstract class limble_webhook_payload { /** @@ -9,6 +11,7 @@ abstract class limble_webhook_payload * @var array $payload */ public array $payload = []; + protected slack $slack; /** * The constructor initializes the payload with the provided data. @@ -17,6 +20,7 @@ abstract class limble_webhook_payload */ public function __construct(array $payload) { + $this->slack = new slack(); // Initialize the Slack class for sending notifications $this->payload = $payload; } diff --git a/services/nginx/app/modules/limble/helpers/limble_webhook_payload_task.php b/services/nginx/app/modules/limble/helpers/limble_webhook_payload_task.php index ee2e24ac..94143426 100644 --- a/services/nginx/app/modules/limble/helpers/limble_webhook_payload_task.php +++ b/services/nginx/app/modules/limble/helpers/limble_webhook_payload_task.php @@ -53,10 +53,85 @@ class limble_webhook_payload_task extends limble_webhook_payload public function __construct(array $payload) { parent::__construct($payload); + $this->slack->send_message('Initializing Limble Webhook Payload Task', 'Limble Webhook Task Initialization'); $this->taskID = (int)($payload['taskID'] ?? 0); $this->status = (string)($payload['status'] ?? ''); $this->category = (string)($payload['category'] ?? ''); $this->user = (string)($payload['user'] ?? ''); $this->taskObject = new limble_task(((new limble())->getTask($payload['taskID'])) ?: []); + $this->slack->send_message('Task has been initialized with ID: ' . $this->taskID, 'Limble Webhook Task Initialized'); + $this->notifyWebhook(); } + + protected function notifyWebhook(): void + { + // Notify the webhook with the task object + $this->slack->send_message(' + Task ID: ' . $this->taskID . ' + Status: ' . $this->status . ' + Category: ' . $this->category . ' + User: ' . $this->user, + 'Limble Webhook Notification' + ); + } + + /** + * CREATED + * DELETED + * CHANGED DUE DATE + * CHANGED ASSIGNMENT + * COMPLETE + * CHANGED COMPLETED TASK + * COMPLETED TASK REOPENED + * CHANGED TASK NAME + * CHANGED TASK DESCRIPTION + * ADDED COMMENT TO TASK + * CUSTOM TAG ADDED TO TASK + * CUSTOM TAG REMOVED FROM TASK + * LOGGED TIME ON TASK + */ + + protected function CREATED(): void + { + // Notify the webhook that a task has been created + $this->slack->send_message('Task Created: ' . $this->taskObject->name, 'Limble Webhook Task Created'); + } + + protected function DELETED(): void + { + // Notify the webhook that a task has been deleted + $this->slack->send_message('Task Deleted: ' . $this->taskObject->name, 'Limble Webhook Task Deleted'); + } + + protected function CHANGED_DUE_DATE(): void + { + // Notify the webhook that the due date of the task has changed + $this->slack->send_message('Task Due Date Changed: ' . $this->taskObject->name, 'Limble Webhook Task Due Date Changed'); + } + + protected function CHANGED_ASSIGNMENT(): void + { + // Notify the webhook that the assignment of the task has changed + $this->slack->send_message('Task Assignment Changed: ' . $this->taskObject->name, 'Limble Webhook Task Assignment Changed'); + } + + protected function COMPLETE(): void + { + // Notify the webhook that the task has been completed + $this->slack->send_message('Task Completed: ' . $this->taskObject->name, 'Limble Webhook Task Completed'); + } + + protected function CHANGED_COMPLETED_TASK(): void + { + // Notify the webhook that a completed task has been changed + $this->slack->send_message('Completed Task Changed: ' . $this->taskObject->name, 'Limble Webhook Completed Task Changed'); + } + + protected function CHANGED_TASK_NAME(): void + { + // Notify the webhook that the task name has changed + $this->slack->send_message('Task Name Changed: ' . $this->taskObject->name, 'Limble Webhook Task Name Changed'); + } + + } \ No newline at end of file diff --git a/services/nginx/app/modules/limble/limble_helpers.php b/services/nginx/app/modules/limble/limble_helpers.php index d8c77b3a..f9244f31 100644 --- a/services/nginx/app/modules/limble/limble_helpers.php +++ b/services/nginx/app/modules/limble/limble_helpers.php @@ -4,9 +4,13 @@ namespace limble; require_once WD . '/modules/limble/helpers/limble_task.php'; require_once WD . '/modules/limble/helpers/limble_tasks.php'; +require_once WD . '/modules/limble/helpers/limble_webhook_payload.php'; +require_once WD . '/modules/limble/helpers/limble_webhook_payload_task.php'; + use limble\helpers\limble_task; use limble\helpers\limble_tasks; +use limble\helpers\limble_webhook_payload; class limble_helpers { @@ -26,5 +30,10 @@ class limble_helpers * @var string $limble_task */ public string $limble_task = limble_task::class; + /** + * The webhook payload task object + * @var string $limble_webhook_payload_task + */ + public string $limble_webhook_payload_task = limble_webhook_payload::class; } \ No newline at end of file diff --git a/services/nginx/app/routes/moduleLimbleRoute.php b/services/nginx/app/routes/moduleLimbleRoute.php index 3a187bf6..222edcac 100644 --- a/services/nginx/app/routes/moduleLimbleRoute.php +++ b/services/nginx/app/routes/moduleLimbleRoute.php @@ -6,6 +6,7 @@ use classes\limble; use classes\response; use classes\router; use classes\slack; +use limble\helpers\limble_webhook_payload_task; use traits\route_t; class moduleLimbleRoute @@ -27,8 +28,18 @@ class moduleLimbleRoute $limble = new limble(); $limble->requireModuleEnabled(); $limble->requireWebhooksEnabled(); - $payload = file_get_contents('php://input'); - $slack->send_message(json_encode($payload), 'Limble Webhook'); + $payload = json_decode(file_get_contents('php://input'), true); + if (json_last_error() !== JSON_ERROR_NONE) { + $response->error('Invalid JSON payload', 400); + } + $slack->send_message('TaskId: ' . ($payload['taskID'] ?? 'Not provided'), 'Limble Webhook Task ID'); + $slack->send_message('Payload: ' . json_encode($payload), 'Limble Webhook Task Payload'); + $task = new limble_webhook_payload_task($payload); + //$task = new $limble->helpers->limble_webhook_payload_task($payload); + $slack->send_message('Limble Webhook Task Received: ' . $task->taskID, 'Limble Webhook Task'); + $slack->send_message('Task Name: ' . $task->taskObject->name, 'Limble Webhook Task Name'); +// $slack->send_message('Task ID: ' . $payload['task_id'], 'Limble Webhook Task ID'); + // Response $response->success('Debug', 200); },