Add page visit Telegram notifications
Some checks failed
Tests / Laravel tests (pull_request) Failing after 6m57s

This commit is contained in:
2026-06-03 23:19:06 +02:00
parent fdc10a0acb
commit bbfc64031f
10 changed files with 434 additions and 45 deletions

View File

@@ -2,12 +2,12 @@
namespace App\Jobs;
use App\Services\TelegramNotificationService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
class NotifyTelegramAboutContactMessage implements ShouldQueue
{
@@ -35,30 +35,15 @@ class NotifyTelegramAboutContactMessage implements ShouldQueue
$this->phone = $phone;
}
public function handle(): void
public function handle(TelegramNotificationService $telegram): void
{
$email = $this->email ?? '';
$phone = $this->phone ?? '';
$text = <<<TEXT
📩 *Nieuw contactbericht ontvangen*
👤 Naam: *{$this->name}*
💬 Bericht:
{$this->message}
📧 Email: {$email}
📱 Telefoon: {$phone}
🌐 IP: {$this->ip}
🧭 User Agent: `{$this->userAgent}`
🕒 Tijdstip: *{now()->format('d-m-Y H:i')}*
TEXT;
Http::post('https://api.telegram.org/bot'.config('services.telegram.bot_token').'/sendMessage', [
'chat_id' => config('services.telegram.chat_id'),
'text' => $text,
'parse_mode' => 'Markdown',
]);
$telegram->notifyContactMessage(
$this->name,
$this->message,
$this->ip,
$this->userAgent,
$this->email,
$this->phone
);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Jobs;
use App\Services\TelegramNotificationService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class NotifyTelegramAboutPageVisit implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* @param array<string, mixed> $visit
*/
public function __construct(
protected array $visit,
protected ?string $ip,
protected ?string $userAgent,
protected ?string $acceptLanguage
) {}
public function handle(TelegramNotificationService $telegram): void
{
$telegram->notifyPageVisit($this->visit, $this->ip, $this->userAgent, $this->acceptLanguage);
}
}

View File

@@ -3,12 +3,12 @@
namespace App\Jobs;
use App\Models\Personalia;
use App\Services\TelegramNotificationService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
class NotifyTelegramAboutPersonaliaClick implements ShouldQueue
{
@@ -27,25 +27,8 @@ class NotifyTelegramAboutPersonaliaClick implements ShouldQueue
$this->userAgent = $userAgent;
}
public function handle(): void
public function handle(TelegramNotificationService $telegram): void
{
$ip = $this->ip ?? '';
$userAgent = $this->userAgent ?? '';
$message = <<<TEXT
👤 *Persoonlijke gegevens bekeken*
Naam: {$this->personalia->value}
IP: {$ip}
User Agent: `{$userAgent}`
📅 Tijdstip: *{now()->format('d-m-Y H:i')}*
TEXT;
Http::post('https://api.telegram.org/bot'.config('services.telegram.bot_token').'/sendMessage', [
'chat_id' => config('services.telegram.chat_id'),
'text' => $message,
'parse_mode' => 'Markdown',
]);
$telegram->notifyPersonaliaClick($this->personalia, $this->ip, $this->userAgent);
}
}