Pada tahap development, pengiriman WhatsApp Reminder biasanya masih dilakukan dengan cara manual, misalnya menekan tombol di dashboard atau menjalankan endpoint tertentu.
Namun pada environment production, sistem seharusnya berjalan otomatis tanpa interaksi user.
Di artikel ini saya mendokumentasikan bagaimana membuat Birthday Reminder WhatsApp otomatis setiap pagi jam 09:00 menggunakan Laravel Scheduler.
Tujuan Automation
Sistem yang akan dibuat memiliki workflow berikut:
Jam 09:00
↓
Laravel Scheduler berjalan
↓
Menjalankan Command Birthday
↓
Fonnte API mengirim WhatsApp
↓
Pesan masuk ke WhatsApp Group
✅Tanpa buka browser
✅ Tanpa klik tombol
✅ Fully otomatis
✅ Konsep Best Practice Laravel
Dalam Laravel tidak disarankan Scheduler memanggil Controller langsung.
Struktur yang benar adalah:
Scheduler
↓
Artisan Command
↓
Service
↓
External API (Fonnte)
✅ STEP 1 — Membuat Artisan Command
Jalankan perintah berikut di terminal:
php artisan make:command SendBirthdayReminder
Laravel akan membuat file:
app/Console/Commands/SendBirthdayReminder.php
✅ STEP 2 — Implementasi Command Birthday Reminder
Isi file command dengan logic pengiriman reminder.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Birthday;
use Carbon\Carbon;
use App\Services\FonnteService;
use Illuminate\Support\Facades\Log;
class SendBirthdayReminder extends Command
{
protected $signature = 'birthday:send';
protected $description = 'Send birthday reminder automatically';
protected $fonnteService;
public function __construct(FonnteService $fonnteService)
{
parent::__construct();
$this->fonnteService = $fonnteService;
}
public function handle()
{
Log::info('Scheduler Birthday Running...');
$today = Carbon::now();
$birthdays = Birthday::where('status','Active')
->whereMonth('tanggal',$today->month)
->whereDay('tanggal',$today->day)
->get();
if ($birthdays->isEmpty()) {
Log::info('Tidak ada birthday hari ini');
return;
}
$message = "🎉 *Bday Reminder*\n\n";
foreach ($birthdays as $b) {
$message .= "🎂 {$b->name}\n";
}
$result = $this->fonnteService->sendGroupMessage($message);
Log::info('Birthday Send Result', $result);
}
}
Command ini bertugas:
✅ Mengambil data birthday hari ini
✅ Membuat pesan WhatsApp
✅ Mengirim otomatis ke Group
✅ STEP 3 — Mendaftarkan Scheduler Laravel
Buka file:
app/Console/Kernel.php
Tambahkan scheduler:
protected function schedule(Schedule $schedule)
{
$schedule->command('birthday:send')
->dailyAt('09:00');
}
✅ STEP 4 — Menjalankan Laravel Scheduler
Ini bagian paling penting.
Laravel Scheduler harus selalu aktif.
Jalankan:
php artisan schedule:work
Jika berhasil akan muncul:
Running scheduled command: birthday:send
✅ STEP 5 — Test Manual Command
Sebelum automation berjalan, lakukan testing manual:
php artisan birthday:send
Belum ada komentar. Jadilah yang pertama!