Files
Kol-Manager/app/Services/Notifications/WahaNotifier.php
I-Fun 22f03ccca7 Add contract management and invoice settings pages
- Created a new Blade view for managing brand contracts with forms for adding and editing contracts, including client and category selection.
- Implemented success message notifications for contract actions.
- Added a new Blade view for invoice settings, allowing customization of invoice number format, header branding, and default values for new invoices.
- Introduced a new PDF view for generating rate cards with customizable styles based on user profile settings.
- Developed a profile management page for rate cards, enabling users to update their identity, appearance, and visibility settings.
2026-04-01 21:47:34 +07:00

63 lines
1.8 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 ?? [];
$endpoint = $config['waha_endpoint'] ?? null;
$session = $config['waha_session'] ?? 'default';
$chatId = $config['chat_id'] ?? null;
$apiKey = $config['api_key'] ?? null;
if (! $endpoint || ! $chatId) {
throw new \RuntimeException('WAHA waha_endpoint and chat_id are required.');
}
$http = Http::timeout(15)->acceptJson()->contentType('application/json');
if ($apiKey) {
$http = $http->withHeaders(['X-Api-Key' => $apiKey]);
}
$response = $http->post($endpoint, [
'chatId' => $chatId,
'text' => $text,
'session' => $session,
]);
if (! $response->successful()) {
$keyHint = $apiKey ? '(api_key set, length=' . strlen($apiKey) . ')' : '(no api_key)';
throw new \RuntimeException(
"WAHA API error {$response->status()} {$keyHint} → " . $response->body()
);
}
}
}