2024-12-25 13:37:49 +07:00
< ? php
namespace App\Helpers ;
use GuzzleHttp\Client ;
use GuzzleHttp\Exception\RequestException ;
use Illuminate\Support\Str ;
class WhatsappHelper
{
2025-01-04 14:09:28 +07:00
public static function approveExpense ( $phones , $expense_number , $url = null )
2024-12-25 13:37:49 +07:00
{
2025-01-04 14:09:28 +07:00
$client = new Client ();
// Ensure the URL is formatted correctly
if ( $url && ! preg_match ( '/^https?:\/\//' , $url )) {
$url = 'https://' . $url ;
}
$data = [];
foreach ( $phones as $phone ) {
$data [] = [
'phone' => $phone ,
'message' => 'Pengajuan pengeluaran anda dengan nomor *' . $expense_number . '* telah disetujui. Silahkan buka link berikut untuk melihat detailnya: ' . $url ,
'source' => 'web'
];
}
$response = $client -> post ( env ( 'WABLAS_HOST' ) . '/api/v2/send-message' , [
'headers' => [
'Authorization' => env ( 'WABLAS_TOKEN' ),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
]
]);
return $response -> getBody () -> getContents ();
2024-12-25 13:37:49 +07:00
}
2025-01-04 14:09:28 +07:00
public static function rejectExpense ( $phones , $expense_number , $url = null )
{
$client = new Client ();
if ( $url && ! preg_match ( '/^https?:\/\//' , $url )) {
$url = 'https://' . $url ;
}
$data = [];
foreach ( $phones as $phone ) {
$data [] = [
'phone' => $phone ,
'message' => 'Pengajuan pengeluaran anda dengan nomor *' . $expense_number . '* telah ditolak. Silahkan buka link berikut untuk melihat detailnya: ' . $url ,
'source' => 'web'
];
}
$response = $client -> post ( env ( 'WABLAS_HOST' ) . '/api/v2/send-message' , [
'headers' => [
'Authorization' => env ( 'WABLAS_TOKEN' ),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
]
]);
return $response -> getBody () -> getContents ();
}
public static function finalApprove ( $phones , $expense_number , $url = null )
{
$client = new Client ();
if ( $url && ! preg_match ( '/^https?:\/\//' , $url )) {
$url = 'https://' . $url ;
}
$data = [];
foreach ( $phones as $phone ) {
$data [] = [
'phone' => $phone ,
'message' => 'Pengajuan pengeluaran anda dengan nomor *' . $expense_number . '* telah ditutup karena telah selesai diproses. Silahkan buka link berikut untuk melihat detailnya: ' . $url ,
'source' => 'web'
];
}
$response = $client -> post ( env ( 'WABLAS_HOST' ) . '/api/v2/send-message' , [
'headers' => [
'Authorization' => env ( 'WABLAS_TOKEN' ),
'Content-Type' => 'application/json'
],
'json' => [
'data' => $data
]
]);
return $response -> getBody () -> getContents ();
}
2024-12-25 13:37:49 +07:00
}