Created
October 20, 2025 03:51
-
-
Save aldhinya/1094d7f598710c67b0989c84196c3471 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Jobs; | |
| use App\Mail\NotifikasiMail; | |
| use App\Services\WhatsAppService; | |
| use Illuminate\Bus\Queueable; | |
| use Illuminate\Contracts\Queue\ShouldQueue; | |
| use Illuminate\Foundation\Bus\Dispatchable; | |
| use Illuminate\Queue\InteractsWithQueue; | |
| use Illuminate\Queue\SerializesModels; | |
| use Illuminate\Support\Facades\Log; | |
| use Illuminate\Support\Facades\Mail; | |
| class NotifikasiJobs implements ShouldQueue | |
| { | |
| use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | |
| protected $data; | |
| /** | |
| * Create a new job instance. | |
| */ | |
| public function __construct($data) | |
| { | |
| $this->data = $data; | |
| } | |
| /** | |
| * Execute the job. | |
| */ | |
| public function handle(): void | |
| { | |
| $data = $this->data; | |
| try { | |
| sleep(3); | |
| $wa = new WhatsAppService(); | |
| $result = $wa->sendMessage( | |
| device_id: 'random', | |
| to: $data['no_wa'], | |
| text: $data['pesan_wa'], | |
| file: NULL // bisa juga path lokal: storage_path('app/public/file.pdf') | |
| ); | |
| Log::info("Response WA: " . json_encode($result)); | |
| } catch (\Throwable $th) { | |
| Log::error($th); | |
| throw new \Exception("Gagal mengirim WA: " . $th->getMessage(), 0, $th); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $dataNotifikasi = [ | |
| 'pesan_wa' => $pesan_wa, | |
| 'no_wa' => $nomor_wa, | |
| ]; | |
| dispatch(new NotifikasiJobs($dataNotifikasi)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment