class AlertService

Traits

Trait aggregating all channel notification traits.

Trait for sending Mail notifications.

Trait for sending Telegram notifications.

Trait for sending Discord notifications.

Methods

void
mailAlert(AlertRecipient|object $recipient, string $type, string $message, array<string,mixed> $details = [], string|null $subject = null)

Send an alert notification via Email.

void
telegramAlert(AlertRecipient|object $recipient, string $type, string $message, array<string,mixed> $details = [], string|null $subject = null)

Send an alert notification via Telegram.

void
discordAlert(AlertRecipient|object $recipient, string $type, string $message, array<string,mixed> $details = [], string|null $subject = null)

Send an alert notification via Discord.

array
flattenAlertDetails(array $details)

Flatten a multidimensional array of alert details into a single-level array.

void
send(string $type, string $message, array $details = [], array $options = [])

Send an alert to configured recipients based on type.

bool
isEnvironmentAllowed()

Check if the current environment is allowed to send alerts.

bool
isInCooldown(string $type, string $address, string $channel, string $message, int $cooldown)

Check if an alert is currently in cooldown for a specific recipient.

void
logCooldownSkip(AlertRecipient $recipient, string $type, string $message, array<string,mixed> $details, string $subject, array<int,array<string,string>> $logRecipients, int $cooldown)

Log that an alert was skipped due to cooldown.

void
sendAlertViaChannel(AlertRecipient $recipient, string $type, string $message, array $details, string $subject)

Dispatch the alert to the specific channel.

void
handleDB(bool $success, array $info)

Record the alert attempt in the database.

void
handleLog(bool $success, array $info)

Log the alert attempt result.

Details

in MailNotification at line 23
void mailAlert(AlertRecipient|object $recipient, string $type, string $message, array<string,mixed> $details = [], string|null $subject = null)

Send an alert notification via Email.

Parameters

AlertRecipient|object $recipient

The recipient object with an email address

string $type

The alert type

string $message

The alert message

array<string,mixed> $details

Additional details

string|null $subject

Optional email subject

Return Value

void

void telegramAlert(AlertRecipient|object $recipient, string $type, string $message, array<string,mixed> $details = [], string|null $subject = null)

Send an alert notification via Telegram.

Parameters

AlertRecipient|object $recipient

The recipient object containing address (chat ID) and bot config

string $type

The alert type

string $message

The alert message

array<string,mixed> $details

Additional details to format in the message

string|null $subject

Optional subject to bold at the top

Return Value

void

void discordAlert(AlertRecipient|object $recipient, string $type, string $message, array<string,mixed> $details = [], string|null $subject = null)

Send an alert notification via Discord.

Parameters

AlertRecipient|object $recipient

The recipient object containing bot config

string $type

The alert type

string $message

The alert message

array<string,mixed> $details

Additional details to include in the message

string|null $subject

Optional subject (used in message formatting)

Return Value

void

in AllChannelsTraits at line 29
array flattenAlertDetails(array $details)

Flatten a multidimensional array of alert details into a single-level array.

Nested keys are concatenated with dots (e.g., 'parent.child').

Parameters

array $details

The details array to flatten

Return Value

array

The flattened array with string values

at line 30
void send(string $type, string $message, array $details = [], array $options = [])

Send an alert to configured recipients based on type.

This method retrieves active recipients for the given alert type, checks for cooldowns, and dispatches alerts via supported channels (Mail, Telegram, Discord). It also handles logging and database recording of the alert attempt.

Parameters

string $type

The type of alert (e.g., 'system_error', 'user_signup')

string $message

The main message body of the alert

array $details

Additional context or data for the alert

array $options

Custom options (e.g., 'mailSubject', 'cooldown')

Return Value

void

Exceptions

InvalidArgumentException
Throwable

at line 87
protected bool isEnvironmentAllowed()

Check if the current environment is allowed to send alerts.

Return Value

bool

True if the current environment is in the allowed list

at line 102
protected bool isInCooldown(string $type, string $address, string $channel, string $message, int $cooldown)

Check if an alert is currently in cooldown for a specific recipient.

Parameters

string $type

Alert type

string $address

Recipient address

string $channel

Channel name

string $message

Alert message

int $cooldown

Cooldown duration in minutes

Return Value

bool

True if a successfully sent alert matching criteria exists within the cooldown period

at line 129
protected void logCooldownSkip(AlertRecipient $recipient, string $type, string $message, array<string,mixed> $details, string $subject, array<int,array<string,string>> $logRecipients, int $cooldown)

Log that an alert was skipped due to cooldown.

Parameters

AlertRecipient $recipient

The recipient object

string $type

Alert type

string $message

Alert message

array<string,mixed> $details

Alert details

string $subject

Alert subject

array<int,array<string,string>> $logRecipients

List of all recipients for logging context

int $cooldown

Cooldown minutes

Return Value

void

at line 157
protected void sendAlertViaChannel(AlertRecipient $recipient, string $type, string $message, array $details, string $subject)

Dispatch the alert to the specific channel.

Parameters

AlertRecipient $recipient
string $type
string $message
array $details
string $subject

Return Value

void

Exceptions

InvalidArgumentException

at line 175
void handleDB(bool $success, array $info)

Record the alert attempt in the database.

Parameters

bool $success

Whether the alert was sent successfully

array $info

Information about the alert (recipient, type, details, etc.)

Return Value

void

at line 203
void handleLog(bool $success, array $info)

Log the alert attempt result.

Parameters

bool $success

Whether the alert was sent successfully

array $info

Information about the alert

Return Value

void