- Implement EmailNotifier for sending batch and test notifications via email. - Implement TelegramNotifier for sending batch and test notifications via Telegram. - Implement WahaNotifier for sending batch and test notifications via WhatsApp using WAHA API. - Create migration for client_categories table and update clients table to include category_id. - Create migration for notification_settings table to manage notification configurations. - Add ClientCategorySeeder to populate default client categories. - Create manifest.json for PWA support. - Implement service worker (sw.js) for caching static assets and offline support. - Add edit event view for modifying scheduled events. - Create search results view for displaying search queries. - Develop notification settings view for configuring notification channels and triggers.
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Notifications;
|
|
|
|
use App\Models\NotificationSetting;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
/**
|
|
* WAHA (WhatsApp HTTP API) — self-hosted WhatsApp bridge.
|
|
* Docs: https://waha.devlike.pro/docs/how-to/send-messages/
|
|
*/
|
|
class WahaNotifier
|
|
{
|
|
public function sendBatch(NotificationSetting $setting, array $messages): void
|
|
{
|
|
foreach ($messages as $message) {
|
|
$this->send($setting, $message);
|
|
}
|
|
}
|
|
|
|
public function sendTest(NotificationSetting $setting): void
|
|
{
|
|
$this->send(
|
|
$setting,
|
|
"🐱 *KOL Manager — Test Notification*\n\nYour WhatsApp channel is configured correctly! 🎉"
|
|
);
|
|
}
|
|
|
|
private function send(NotificationSetting $setting, string $text): void
|
|
{
|
|
$config = $setting->config ?? [];
|
|
$url = rtrim($config['waha_url'] ?? '', '/');
|
|
$session = $config['waha_session'] ?? 'default';
|
|
$phone = $config['phone'] ?? null;
|
|
|
|
if (! $url || ! $phone) {
|
|
throw new \RuntimeException('WAHA waha_url and phone are required.');
|
|
}
|
|
|
|
// Normalise phone: strip non-digits, ensure no leading +
|
|
$chatId = preg_replace('/[^0-9]/', '', $phone) . '@c.us';
|
|
|
|
$response = Http::timeout(15)->post("{$url}/api/sendText", [
|
|
'session' => $session,
|
|
'chatId' => $chatId,
|
|
'text' => $text,
|
|
]);
|
|
|
|
if (! $response->successful()) {
|
|
throw new \RuntimeException('WAHA API error: ' . $response->body());
|
|
}
|
|
}
|
|
}
|