fixed nextcloud and wa api

This commit is contained in:
Jagad R R
2025-02-16 20:18:36 +07:00
parent 838e170c6f
commit b3ce444c97
6 changed files with 175 additions and 83 deletions
+7 -12
View File
@@ -29,7 +29,7 @@ class NextCloudHelper
$currentPath .= '/' . $folder; // Add the current folder to the path
// Build the URL to create the folder
$url = rtrim($baseUrl, '/') . "/mktia/remote.php/dav/files/{$username}" . $currentPath;
$url = rtrim($baseUrl, '/') . "/remote.php/dav/files/{$username}" . $currentPath;
try {
// Attempt to create the current folder
@@ -78,7 +78,7 @@ class NextCloudHelper
}
$client = new Client();
$url = rtrim($baseUrl, '/') . "/mktia/remote.php/dav/files/{$username}/" . ltrim($folderPath, '/') . '/' . $fileName;
$url = rtrim($baseUrl, '/') . "/remote.php/dav/files/{$username}/" . ltrim($folderPath, '/') . '/' . $fileName;
try {
// Check if the file is an image
@@ -130,14 +130,9 @@ class NextCloudHelper
public static function getFileUrl($filePath)
{
$baseUrl = env('NEXT_CLOUD_URL');
$username = env('NEXT_CLOUD_USERNAME');
// Build the user-specific WebDAV file URL
$relativePath = "/mktia/remote.php/dav/files/{$username}/" . ltrim($filePath, '/');
// Return the full accessible URL
return rtrim($baseUrl, '/') . '/' . $relativePath;
// Instead of returning the direct Nextcloud URL,
// return a URL to your own download route.
return route('admin.nextcloud.download', ['file' => base64_encode($filePath)]);
}
public static function getNextcloudFile($filePath)
@@ -171,7 +166,7 @@ class NextCloudHelper
public static function createUser($baseUrl, $adminUsername, $adminPassword, $userId, $password, $displayName, $email)
{
$client = new Client();
$url = rtrim($baseUrl, '/') . "/mktia/ocs/v1.php/cloud/users";
$url = rtrim($baseUrl, '/') . "/ocs/v1.php/cloud/users";
try {
$response = $client->request('POST', $url, [
@@ -214,7 +209,7 @@ class NextCloudHelper
public static function addUserToGroup($baseUrl, $adminUsername, $adminPassword, $userId, $groupName)
{
$client = new Client();
$url = rtrim($baseUrl, '/') . "/mktia/ocs/v1.php/cloud/groups/{$groupName}";
$url = rtrim($baseUrl, '/') . "/ocs/v1.php/cloud/groups/{$groupName}";
try {
$response = $client->request('POST', $url, [
+91 -61
View File
@@ -37,19 +37,24 @@ class WhatsappHelper
];
}
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
try {
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
return $response->getBody()->getContents();
return $response->getBody()->getContents();
} catch (\Exception $e) {
AuditTrailHelper::AddAuditTrail('Error', 'Failed to send WhatsApp message at Form (' . $expense_number . ')');
return null;
}
}
public static function approve2Expense($phones, $expense_number, $url = null, $tanggal, $total, $name)
@@ -81,19 +86,24 @@ class WhatsappHelper
];
}
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
try {
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
return $response->getBody()->getContents();
return $response->getBody()->getContents();
} catch (\Exception $e) {
AuditTrailHelper::AddAuditTrail('Error', 'Failed to send WhatsApp message at Form (' . $expense_number . ')');
return null;
}
}
public static function rejectExpense($phones, $expense_number, $url = null, $tanggal, $total, $name)
@@ -125,19 +135,24 @@ class WhatsappHelper
];
}
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
try {
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
return $response->getBody()->getContents();
return $response->getBody()->getContents();
} catch (\Exception $e) {
AuditTrailHelper::AddAuditTrail('Error', 'Failed to send WhatsApp message at Form (' . $expense_number . ')');
return null;
}
}
public static function finalApprove($phones, $expense_number, $url = null, $tanggal, $total, $name)
@@ -169,19 +184,24 @@ class WhatsappHelper
];
}
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
try {
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
return $response->getBody()->getContents();
return $response->getBody()->getContents();
} catch (\Exception $e) {
AuditTrailHelper::AddAuditTrail('Error', 'Failed to send WhatsApp message at Form (' . $expense_number . ')');
return null;
}
}
public static function newExpense($phones, $expense_number, $url = null, $tanggal, $total, $name)
@@ -213,18 +233,28 @@ class WhatsappHelper
];
}
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
dd(env('WABLAS_HOST'), env('WABLAS_TOKEN'), $data);
return $response->getBody()->getContents();
try {
// Send the request to the WABLAS API
$response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [
'headers' => [
'Authorization' => env('WABLAS_TOKEN'),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
],
'verify' => false,
]);
dd($response->getBody()->getContents());
return $response->getBody()->getContents();
} catch (\Exception $e) {
dd($e->getMessage());
AuditTrailHelper::AddAuditTrail('Error', 'Failed to send WhatsApp message at Form (' . $expense_number . ')');
return null;
}
}
}
}