Files
zemailnator/app/NotifyMe.php
idevakk 0d33c57b32 feat(notifications): implement comprehensive telegram notifications for payment providers
- Add NotifyMe trait with centralized Telegram bot integration
  - Implement webhook notifications for Polar, OxaPay, and ActivationKey providers
  - Add subscription lifecycle notifications (create, activate, cancel, pause, resume)
  - Enhance Polar webhook processing with user context and error handling
  - Fix subscription.updated and subscription.canceled webhook column errors
  - Add idempotent webhook processing to prevent duplicate handling
2025-12-08 09:25:19 -08:00

39 lines
889 B
PHP

<?php
namespace App;
use Exception;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
trait NotifyMe
{
public function sendTelegramNotification($message): bool
{
$botToken = config('app.notify_tg_bot_token');
$chatId = config('app.notify_tg_chat_id');
if (! $botToken || ! $chatId) {
Log::error('Telegram bot token or chat ID not configured');
return false;
}
$url = "https://api.telegram.org/bot{$botToken}/sendMessage";
$data = [
'chat_id' => $chatId,
'text' => $message,
'parse_mode' => 'HTML',
];
try {
return Http::post($url, $data)->successful();
} catch (Exception $e) {
Log::error('Failed to send Telegram notification: '.$e->getMessage());
return false;
}
}
}