Penambahan Sementara Pengajuan Presensi WhatsApp
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class WhatsAppService
|
||||
{
|
||||
private string $baseUrl = 'https://chat.api.co.id';
|
||||
|
||||
private string $token = 'apicoid_live_7J0vmW5Sbk2dBBAEIEDtdc4tG4fOswy3Seblz_nKZqk';
|
||||
|
||||
public function sendPengajuanAbsenNotification(
|
||||
string $nomorTujuan,
|
||||
string $namaAtasan,
|
||||
string $namaPemohon,
|
||||
string $nipPemohon,
|
||||
int $jumlahHari,
|
||||
string $tanggalMulai,
|
||||
string $tanggalSelesai,
|
||||
string $keterangan,
|
||||
string $link
|
||||
): bool {
|
||||
try {
|
||||
$response = Http::withToken($this->token)
|
||||
->post("{$this->baseUrl}/api/v1/public/messages/send", [
|
||||
'phone_number' => $nomorTujuan,
|
||||
'channel' => 'whatsapp',
|
||||
'message_type' => 'template',
|
||||
'template' => [
|
||||
'name' => 'pengajuan_absen',
|
||||
'language' => ['code' => 'id'],
|
||||
'components' => [
|
||||
[
|
||||
'type' => 'body',
|
||||
'parameters' => [
|
||||
['type' => 'text', 'text' => $namaAtasan],
|
||||
['type' => 'text', 'text' => $namaPemohon],
|
||||
['type' => 'text', 'text' => $nipPemohon],
|
||||
['type' => 'text', 'text' => (string) $jumlahHari],
|
||||
['type' => 'text', 'text' => $tanggalMulai],
|
||||
['type' => 'text', 'text' => $tanggalSelesai],
|
||||
['type' => 'text', 'text' => $keterangan],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'button',
|
||||
'sub_type' => 'url',
|
||||
'index' => '0',
|
||||
'parameters' => [
|
||||
['type' => 'text', 'text' => $link],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
} catch (Throwable $th) {
|
||||
Log::error('WhatsApp sendPengajuanAbsenNotification : '.$th->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $response->successful()) {
|
||||
Log::error("WhatsApp sendPengajuanAbsenNotification gagal: HTTP {$response->status()} - {$response->body()}");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user