Files
2026-04-24 21:40:10 -05:00

72 lines
2.3 KiB
PHP

<?php
namespace App\Http\Livewire\Whatsapp;
use App\Models\WhatsappSystemConfig;
use Livewire\Component;
use Jantinnerezo\LivewireAlert\LivewireAlert;
class ShowConfiguracionBot extends Component
{
use LivewireAlert;
public string $whatsapp_token = '';
public string $phone_number_id = '';
public string $whatsapp_api_url = '';
public string $webhook_verify_token = '';
public string $bot_enabled = '1';
public string $welcome_message = '';
public string $default_no_match = '';
public string $advisor_message = '';
public string $business_hours_enabled = '0';
public string $business_hours_start = '';
public string $business_hours_end = '';
protected $rules = [
'whatsapp_token' => 'required|string',
'phone_number_id' => 'required|string',
'whatsapp_api_url' => 'required|url',
'webhook_verify_token' => 'required|string',
'welcome_message' => 'required|string|max:1000',
'default_no_match' => 'required|string|max:500',
'advisor_message' => 'required|string|max:500',
];
public function mount(): void
{
$keys = [
'whatsapp_token', 'phone_number_id', 'whatsapp_api_url',
'webhook_verify_token', 'bot_enabled', 'welcome_message',
'default_no_match', 'advisor_message', 'business_hours_enabled',
'business_hours_start', 'business_hours_end',
];
foreach ($keys as $key) {
$this->{$key} = WhatsappSystemConfig::get($key);
}
}
public function save(): void
{
$this->validate();
$keys = [
'whatsapp_token', 'phone_number_id', 'whatsapp_api_url',
'webhook_verify_token', 'bot_enabled', 'welcome_message',
'default_no_match', 'advisor_message', 'business_hours_enabled',
'business_hours_start', 'business_hours_end',
];
foreach ($keys as $key) {
WhatsappSystemConfig::set($key, $this->{$key});
}
$this->alert('success', 'Configuración guardada correctamente.');
}
public function render()
{
return view('livewire.whatsapp.show-configuracion-bot');
}
}