Expand Limble module with new webhook payload helpers, JSON validation, Slack notifications, and task-specific webhook handling logic.

This commit is contained in:
Jepp9350
2025-06-12 19:56:59 +02:00
parent 9371883138
commit 978f51d8cd
4 changed files with 101 additions and 2 deletions
@@ -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;
}
@@ -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');
}
}
@@ -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;
}
@@ -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);
},