* Discord notifications for events #433 * Style fixes * Check for blank webhook urls and disable * Cleanup items after review * Changes and fixes * Style fixes * Don't load env for testing * Fix status text * Refactor saving fields/fares so events get the latest data * Cleanup * Style fixes
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Channels\Discord;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Support\HttpClient;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Psr7;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Discord
|
||||
{
|
||||
private $httpClient;
|
||||
|
||||
public function __construct(HttpClient $httpClient)
|
||||
{
|
||||
$this->httpClient = $httpClient;
|
||||
}
|
||||
|
||||
public function send($notifiable, Notification $notification)
|
||||
{
|
||||
$message = $notification->toDiscordChannel($notifiable);
|
||||
if ($message === null || empty($message->webhook_url)) {
|
||||
Log::debug('Discord notifications not configured, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $message->toArray();
|
||||
$this->httpClient->post($message->webhook_url, $data);
|
||||
} catch (RequestException $e) {
|
||||
$response = Psr7\Message::toString($e->getResponse());
|
||||
Log::error('Error sending Discord notification: '.$e->getMessage().', '.$response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user