Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aldhinya/1094d7f598710c67b0989c84196c3471 to your computer and use it in GitHub Desktop.

Select an option

Save aldhinya/1094d7f598710c67b0989c84196c3471 to your computer and use it in GitHub Desktop.
<?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);
}
}
}
$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