57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\Whatsapp\WhatsappCloudClient;
|
|
use Illuminate\Console\Command;
|
|
|
|
class WhatsappTestSend extends Command
|
|
{
|
|
protected $signature = 'whatsapp:test {--to= : Recipient MSISDN, default ADMIN_PHONE_NUMBER}';
|
|
|
|
protected $description = 'Send the configured WhatsApp Cloud template to a test number';
|
|
|
|
public function handle()
|
|
{
|
|
$client = new WhatsappCloudClient();
|
|
|
|
if (!$client->isConfigured()) {
|
|
$this->error('Set WHATSAPP_TOKEN and WHATSAPP_PHONE_NUMBER_ID in .env first.');
|
|
return 1;
|
|
}
|
|
|
|
$to = $client->normalizeMsisdn($this->option('to') ?: env('ADMIN_PHONE_NUMBER'));
|
|
if (!$to) {
|
|
$this->error('Pass --to=60193450165 or set ADMIN_PHONE_NUMBER.');
|
|
return 1;
|
|
}
|
|
|
|
$template = config('whatsapp.template', 'hello_world');
|
|
$lang = config('whatsapp.template_lang', 'en_US');
|
|
$bodyParams = [];
|
|
|
|
if (strtolower($template) !== 'hello_world') {
|
|
// pembiayaan_online_paid: SAG, amaun, bank, 4 digit akhir, tarikh, rujukan
|
|
$bodyParams = [
|
|
'TEST-SAG',
|
|
'100.00',
|
|
'Maybank',
|
|
'1234',
|
|
date('d/m/Y'),
|
|
'TEST-REF',
|
|
];
|
|
}
|
|
|
|
$this->info("Sending {$template} ({$lang}) to {$to} …");
|
|
$response = $client->sendTemplate($to, $template, $lang, $bodyParams);
|
|
|
|
if ($response->successful()) {
|
|
$this->info('OK ' . $response->status() . ' ' . $response->body());
|
|
return 0;
|
|
}
|
|
|
|
$this->error('FAIL ' . $response->status() . ' ' . $response->body());
|
|
return 1;
|
|
}
|
|
}
|