Deploy on 2026-06-05 16:08:53
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services\Crawler;
|
||||
|
||||
use App\Services\Database\Connection;
|
||||
use App\Services\Database\ActivityLogger;
|
||||
use App\Services\Notification\TelegramNotifier;
|
||||
use PDO;
|
||||
use Throwable;
|
||||
|
||||
@@ -13,17 +14,20 @@ class Collector
|
||||
private RssParser $rssParser;
|
||||
private AiAnalyzer $aiAnalyzer;
|
||||
private ActivityLogger $logger;
|
||||
private TelegramNotifier $notifier;
|
||||
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
RssParser $rssParser,
|
||||
AiAnalyzer $aiAnalyzer,
|
||||
ActivityLogger $logger
|
||||
ActivityLogger $logger,
|
||||
TelegramNotifier $notifier
|
||||
) {
|
||||
$this->pdo = $connection->getPdo();
|
||||
$this->rssParser = $rssParser;
|
||||
$this->aiAnalyzer = $aiAnalyzer;
|
||||
$this->logger = $logger;
|
||||
$this->notifier = $notifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,6 +80,12 @@ class Collector
|
||||
'new_organizations' => $results['new_organizations'],
|
||||
]));
|
||||
|
||||
// Send Telegram notification if enabled
|
||||
if ($this->getSetting('telegram_enabled') === '1') {
|
||||
$this->notifier->loadSettings();
|
||||
$this->notifier->notifyCollectorResults($results);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
@@ -203,6 +213,25 @@ class Collector
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger Telegram notification if enabled
|
||||
if ($this->getSetting('telegram_enabled') === '1') {
|
||||
$orgName = '';
|
||||
if ($orgId) {
|
||||
$orgStmt = $this->pdo->prepare("SELECT name FROM organizations WHERE id = ?");
|
||||
$orgStmt->execute([$orgId]);
|
||||
$orgName = $orgStmt->fetchColumn() ?: '';
|
||||
}
|
||||
$this->notifier->loadSettings();
|
||||
$this->notifier->notifyNewOpportunity([
|
||||
'title' => $entry['title'],
|
||||
'type' => $analysis['opportunity_type'] ?? $analysis['type'] ?? 'other',
|
||||
'score' => $score,
|
||||
'url' => $entry['url'],
|
||||
'description' => $analysis['summary'] ?? $entry['description'],
|
||||
'org_name' => $orgName,
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (Throwable $e) {
|
||||
// Log but don't fail
|
||||
}
|
||||
@@ -246,4 +275,19 @@ class Collector
|
||||
);
|
||||
return $stmt->fetchAll() ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a setting by key from the database.
|
||||
*/
|
||||
private function getSetting(string $key): ?string
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("SELECT `value` FROM settings WHERE `key` = ?");
|
||||
$stmt->execute([$key]);
|
||||
$val = $stmt->fetchColumn();
|
||||
return $val !== false ? $val : null;
|
||||
} catch (Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user