Files
Kol-Manager/app/Services/Notifications/TelegramNotifier.php
I-Fun d3c35ad730 feat: Add notification services for Email, Telegram, and WhatsApp
- 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.
2026-04-01 12:46:58 +07:00

51 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\Notifications;
use App\Models\NotificationSetting;
use Illuminate\Support\Facades\Http;
class TelegramNotifier
{
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 Telegram channel is configured correctly! 🎉"
);
}
private function send(NotificationSetting $setting, string $text): void
{
$config = $setting->config ?? [];
$botToken = $config['bot_token'] ?? null;
$chatId = $config['chat_id'] ?? null;
if (! $botToken || ! $chatId) {
throw new \RuntimeException('Telegram bot_token and chat_id are required.');
}
$response = Http::timeout(10)->post(
"https://api.telegram.org/bot{$botToken}/sendMessage",
[
'chat_id' => $chatId,
'text' => $text,
'parse_mode' => 'Markdown',
]
);
if (! $response->successful()) {
throw new \RuntimeException('Telegram API error: ' . $response->body());
}
}
}