Fix data not showing up for live map (#1223)
* Fix data not showing up for live map * StyleCI fixes
This commit is contained in:
38
app/Notifications/Channels/Discord/DiscordWebhook.php
Normal file
38
app/Notifications/Channels/Discord/DiscordWebhook.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 DiscordWebhook
|
||||
{
|
||||
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) {
|
||||
$request = Psr7\Message::toString($e->getRequest());
|
||||
$response = Psr7\Message::toString($e->getResponse());
|
||||
Log::error('Error sending Discord notification: request: '.$e->getMessage().', '.$request);
|
||||
Log::error('Error sending Discord notification: response: '.$response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user