diff --git a/lib/ApplicationAlerters.php b/lib/ApplicationAlerters.php index f5ccc93..fc7cdbe 100644 --- a/lib/ApplicationAlerters.php +++ b/lib/ApplicationAlerters.php @@ -8,46 +8,50 @@ use Serhiy\Pushover\Api\Message\Message as PushoverMessage; use Serhiy\Pushover\Api\Message\Notification as PushoverNotification; final class ApplicationAlerters { - /** - * @param string[] $key Hook key (unused) - * @param mixed[] $params Array of [user, tilde, message] - * @return mixed[] Array of [user, tilde, message] - */ - public static function pushover(array $key, array $params): array { - list($user, $tilde, $message) = $params; + /** + * @param string[] $key Hook key (unused) + * @param mixed[] $params Array of [user, tilde, message] + * @return mixed[] Array of [user, tilde, message] + */ + public static function pushover(array $key, array $params): array { + list($user, $tilde, $message) = $params; - $application = new Pushover\Application($_ENV[IX_ENVBASE . '_PUSHOVER_API_TOKEN']); - $recipient = new Pushover\Recipient($_ENV[IX_ENVBASE . '_PUSHOVER_USER_KEY']); - $pushovermessage = new PushoverMessage( - "from {$user}@{$tilde}\n> {$message}", - 'new neotel application', - ); - $notification = new PushoverNotification($application, $recipient, $pushovermessage); - $response = $notification->push(); + $application = new Pushover\Application($_ENV[IX_ENVBASE . '_PUSHOVER_API_TOKEN']); + $pushovermessage = new PushoverMessage( + "from {$user}@{$tilde}\n> {$message}", + 'new neotel application', + ); - return [$user, $tilde, $message]; - } + $pushoverusers = explode(',', $_ENV[IX_ENVBASE . '_PUSHOVER_USER_KEYS']); + foreach ($pushoverusers as $userkey) { + $recipient = new Pushover\Recipient($userkey); + $notification = new PushoverNotification($application, $recipient, $pushovermessage); + $response = $notification->push(); + } - /** - * @param string[] $key Hook key (unused) - * @param mixed[] $params Array of [user, tilde, message] - * @return mixed[] Array of [user, tilde, message] - */ - public static function discord(array $key, array $params): array { - list($user, $tilde, $message) = $params; + return [$user, $tilde, $message]; + } - $data = json_encode([ - "content" => "From `{$user}@{$tilde}` \n> {$message}", - ]); + /** + * @param string[] $key Hook key (unused) + * @param mixed[] $params Array of [user, tilde, message] + * @return mixed[] Array of [user, tilde, message] + */ + public static function discord(array $key, array $params): array { + list($user, $tilde, $message) = $params; - $curl_opts = [ - CURLOPT_HTTPHEADER => ["Content-Type: application/json"], - CURLOPT_POST => 1, - CURLOPT_POSTFIELDS => $data, - ]; + $data = json_encode([ + "content" => "From `{$user}@{$tilde}` \n> {$message}", + ]); - $response = CurlHelpers::fetchUrl($_ENV[IX_ENVBASE . "_DISCORD_WEBHOOK_URL"], $curl_opts, true); + $curl_opts = [ + CURLOPT_HTTPHEADER => ["Content-Type: application/json"], + CURLOPT_POST => 1, + CURLOPT_POSTFIELDS => $data, + ]; - return [$user, $tilde, $message]; - } + $response = CurlHelpers::fetchUrl($_ENV[IX_ENVBASE . "_DISCORD_WEBHOOK_URL"], $curl_opts, true); + + return [$user, $tilde, $message]; + } } diff --git a/lib/Configuration.php b/lib/Configuration.php index f3f8d3f..364c34f 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -44,7 +44,7 @@ class Configuration { // Pushover application and user keys $dotenv->required(IX_ENVBASE . '_PUSHOVER_API_TOKEN')->notEmpty(); - $dotenv->required(IX_ENVBASE . '_PUSHOVER_USER_KEY')->notEmpty(); + $dotenv->required(IX_ENVBASE . '_PUSHOVER_USER_KEYS')->notEmpty(); // Discord webhook URL $dotenv->required(IX_ENVBASE . '_DISCORD_WEBHOOK_URL')->notEmpty();