Add xlvask_parser_h_nger to XLVask helpers imports for extended parsing functionalities
This commit is contained in:
@@ -5,6 +5,7 @@ require_once WD . '/modules/limble/interfaces/limble_endpoints_i.php';
|
||||
require_once WD . '/modules/limble/classes/limble_request.php';
|
||||
|
||||
use Exception;
|
||||
use limble\helpers\limble_tasks_pagination;
|
||||
use limble_endpoints_i;
|
||||
|
||||
abstract class limble_endpoints extends limble_request implements limble_endpoints_i
|
||||
@@ -14,14 +15,11 @@ abstract class limble_endpoints extends limble_request implements limble_endpoin
|
||||
* @inheritDoc
|
||||
* @throws Exception If the module is not enabled
|
||||
*/
|
||||
public function listTasks(): array
|
||||
public function listTasks(limble_tasks_pagination $pagination): array
|
||||
{
|
||||
$this->requireModuleEnabled();
|
||||
$url = $this->config->api_url . '/tasks';
|
||||
$params = [
|
||||
// 'status' => 'open',
|
||||
// 'limit' => 100,
|
||||
];
|
||||
$params = [...$pagination->getParams()];
|
||||
return $this->sendRequest(
|
||||
$url,
|
||||
'GET',
|
||||
@@ -51,6 +49,22 @@ abstract class limble_endpoints extends limble_request implements limble_endpoin
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws Exception If the module is not enabled
|
||||
*/
|
||||
public function getTaskInstructions(int $taskId): array
|
||||
{
|
||||
$this->requireModuleEnabled();
|
||||
$url = $this->config->api_url . '/tasks/' . $taskId . '/instructions';
|
||||
return $this->sendRequest(
|
||||
$url,
|
||||
'GET',
|
||||
[],
|
||||
[self::getAuthHeader(), 'Content-Type: application/json']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws Exception If the module is not enabled
|
||||
@@ -59,12 +73,14 @@ abstract class limble_endpoints extends limble_request implements limble_endpoin
|
||||
{
|
||||
$this->requireModuleEnabled();
|
||||
$url = $this->config->api_url . '/tasks';
|
||||
// Set the taskId as a pagination parameter
|
||||
$pagination = new limble_tasks_pagination();
|
||||
$pagination->tasks = $taskId;
|
||||
$pagination->limit = 1; // Limit to 1 task
|
||||
return $this->sendRequest(
|
||||
$url,
|
||||
'GET',
|
||||
[
|
||||
'cursor' => $taskId,
|
||||
],
|
||||
[...$pagination->getParams()],
|
||||
[self::getAuthHeader(), 'Content-Type: application/json']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace limble\helpers;
|
||||
|
||||
class limble_object_helper
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace limble\helpers;
|
||||
|
||||
abstract class limble_pagination_helper
|
||||
{
|
||||
/**
|
||||
* Limit of items per page.
|
||||
* @var int $limit
|
||||
*/
|
||||
public int $limit = 100;
|
||||
/**
|
||||
* Page number to display.
|
||||
* @var int $page
|
||||
*/
|
||||
public int $page = 1;
|
||||
|
||||
public function getParams(): array
|
||||
{
|
||||
return array_filter((array)$this, function ($value) {
|
||||
return is_int($value) || is_string($value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace limble\helpers;
|
||||
|
||||
class limble_task_comment extends limble_object_helper
|
||||
{
|
||||
/**
|
||||
* The unique identifier for the comment.
|
||||
* @var int $commentID
|
||||
*/
|
||||
public int $commentID;
|
||||
/**
|
||||
* The content of the comment.
|
||||
* @var string $comment
|
||||
*/
|
||||
public string $comment;
|
||||
/**
|
||||
* An array of files associated with the comment.
|
||||
* @var array $commentFiles
|
||||
*/
|
||||
public array $commentFiles;
|
||||
/**
|
||||
* The timestamp when the comment was created.
|
||||
* @var int $timestamp
|
||||
*/
|
||||
public int $timestamp;
|
||||
/**
|
||||
* The unique identifier for the user who created the comment.
|
||||
* @var int $userID
|
||||
*/
|
||||
public int $userID;
|
||||
/**
|
||||
* The email address associated with the comment, if any.
|
||||
* @var string|null $commentEmailAddress
|
||||
*/
|
||||
public ?string $commentEmailAddress;
|
||||
/**
|
||||
* Indicates whether the comment should be shown to external users.
|
||||
* @var bool $showExternalUsers
|
||||
*/
|
||||
public bool $showExternalUsers;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace limble\helpers;
|
||||
|
||||
class limble_task_instruction extends limble_object_helper
|
||||
{
|
||||
/**
|
||||
* The unique identifier for the instruction.
|
||||
* @var int $instructionID
|
||||
*/
|
||||
public int $instructionID;
|
||||
/**
|
||||
* The unique identifier for the task associated with this instruction.
|
||||
* @var int $taskID
|
||||
*/
|
||||
public int $taskID;
|
||||
/**
|
||||
* The unique identifier for the parent instruction, if any.
|
||||
* @var int $parentInstructionID
|
||||
*/
|
||||
public int $parentInstructionID;
|
||||
/**
|
||||
* The instruction text that describes what needs to be done.
|
||||
* @var string $instruction
|
||||
*/
|
||||
public string $instruction;
|
||||
/**
|
||||
* The type of instruction, represented as an integer.
|
||||
* @var int $type
|
||||
*/
|
||||
public int $type;
|
||||
/**
|
||||
* An array of options related to the instruction.
|
||||
* @var array $options
|
||||
*/
|
||||
public array $options;
|
||||
/**
|
||||
* Indicates whether a response is required for this instruction.
|
||||
* @var bool $response
|
||||
*/
|
||||
public bool $response;
|
||||
/**
|
||||
* An array of files associated with the instruction.
|
||||
* @var array $instructionFiles
|
||||
*/
|
||||
public array $instructionFiles;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace limble\helpers;
|
||||
|
||||
class limble_tasks_pagination extends limble_pagination_helper
|
||||
{
|
||||
/**
|
||||
* The unique identifier for the task.
|
||||
* @note This is used to specify a specific task when retrieving pagination data.
|
||||
* @see limble_task::taskID
|
||||
* @var int $tasks
|
||||
*/
|
||||
public int $tasks;
|
||||
}
|
||||
@@ -53,26 +53,26 @@ 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->taskObject = new limble_task(((new limble())->getTask($payload['taskID']))[0] ?? []);
|
||||
$this->notifyWebhook();
|
||||
}
|
||||
|
||||
protected function notifyWebhook(): void
|
||||
{
|
||||
// Generate the message to notify the webhook
|
||||
$message = "";
|
||||
$message .= "Task ID: " . $this->taskID . "\n";
|
||||
$message .= "Name: " . $this->taskObject->name . "\n";
|
||||
$message .= "Description: " . $this->taskObject->description . "\n";
|
||||
$message .= "User: " . $this->user . "\n";
|
||||
$message .= "Status: " . $this->status . "\n";
|
||||
$message .= "Category: " . $this->category . "\n";
|
||||
// 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'
|
||||
);
|
||||
$this->slack->send_message($message, 'Limble Webhook Task Notification');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
<?php
|
||||
|
||||
|
||||
use limble\helpers\limble_task_instruction;
|
||||
use limble\helpers\limble_tasks_pagination;
|
||||
|
||||
interface limble_endpoints_i
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the tasks from the limble API
|
||||
* @param limble_tasks_pagination $pagination
|
||||
* @return array
|
||||
*/
|
||||
public function listTasks(): array;
|
||||
public function listTasks(limble_tasks_pagination $pagination): array;
|
||||
|
||||
/**
|
||||
* Get a specific task from the limble API
|
||||
@@ -17,6 +21,14 @@ interface limble_endpoints_i
|
||||
*/
|
||||
public function getTask(int $taskId): array;
|
||||
|
||||
/**
|
||||
* Get the list of task instructions from the limble API
|
||||
* @param int $taskId
|
||||
* @return limble_task_instruction[]
|
||||
* @see limble_task_instruction
|
||||
*/
|
||||
public function getTaskInstructions(int $taskId): array;
|
||||
|
||||
|
||||
/**
|
||||
* Get the auth header for the API
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace limble;
|
||||
|
||||
require_once WD . '/modules/limble/helpers/limble_object_helper.php';
|
||||
require_once WD . '/modules/limble/helpers/limble_pagination_helper.php';
|
||||
require_once WD . '/modules/limble/helpers/limble_tasks_pagination.php';
|
||||
require_once WD . '/modules/limble/helpers/limble_task_instruction.php';
|
||||
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';
|
||||
|
||||
@@ -6,6 +6,7 @@ use classes\limble;
|
||||
use classes\response;
|
||||
use classes\router;
|
||||
use classes\slack;
|
||||
use limble\helpers\limble_tasks_pagination;
|
||||
use limble\helpers\limble_webhook_payload_task;
|
||||
use traits\route_t;
|
||||
|
||||
@@ -21,7 +22,6 @@ class moduleLimbleRoute
|
||||
$this->post('/modules/limble/webhook/task', function () {
|
||||
global $response;
|
||||
$slack = new slack();
|
||||
$slack->send_message('Limble Webhook Task Triggered', 'Limble Webhook');
|
||||
//TODO: Add authentication of some sort here
|
||||
//self::requirePermission('modules_limble_webhooks_task');
|
||||
// Check if the module is enabled
|
||||
@@ -32,14 +32,7 @@ class moduleLimbleRoute
|
||||
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);
|
||||
},
|
||||
@@ -56,8 +49,10 @@ class moduleLimbleRoute
|
||||
// Check if the module is enabled
|
||||
$limble = new limble();
|
||||
$limble->requireModuleEnabled();
|
||||
$pagination = new limble_tasks_pagination();
|
||||
//$pagination->tasks = 2;
|
||||
// Get the tasks
|
||||
$tasks = $limble->getTasks()->formatTasks($limble->listTasks());
|
||||
$tasks = $limble->getTasks()->formatTasks($limble->listTasks($pagination));
|
||||
// Response
|
||||
$response->success($tasks, 200);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user