isError); $body = [ "content"=> "", "tts"=> false, "embeds" => [ [ "id" => 652627557, "title" => $notification->getTitle()->toString(), "description" => $notification->getBody()->toMarkdownString(), "color" => self::EMBED_COLOR[(int)$notification->isError], "url" => $notification->getLinkURL(), ], ], "username" => "Datboi", "avatar_url" => "https://media1.giphy.com/media/yDTWAecZcB2Jq/200w.gif?cid=6c09b952f68kz3wnkqsmyha8e7xrpe8n2kx0nkf2b8cir6am&rid=200w.gif&ct=g", ]; if ($notification->getImageURL() !== null) { $body["embeds"][0]["image"] = [ "url" => "attachment://image.png" ]; } $payloadJson = json_encode($body); $formData = [ 'payload_json' => $payloadJson, ]; if ($notification->getImageURL() !== null) { $formData['file'] = curl_file_create($notification->getImageProjectPath(), 'image/png', 'image.png'); } $ch = curl_init($webHookUrl); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data')); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $formData); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); } private static function getDiscordWebHookUrl(bool $isError): string { $generalWebHookUrlKey = 'discord_webhook_url'; $generalWebHookUrl = Cache::rememberForever($generalWebHookUrlKey, function () use ($generalWebHookUrlKey) { return JobInfo::where('key', $generalWebHookUrlKey)->first()->value; }); if ($generalWebHookUrl === null) { throw new \Exception("Le webhook discord n'a pas été configuré"); } if ($isError) { $errorWebHookUrlKey = 'discord_error_webhook_url'; $errorWebHookUrl = Cache::rememberForever($errorWebHookUrlKey, function () use ($errorWebHookUrlKey) { return JobInfo::where('key', $errorWebHookUrlKey)->first()->value; }); return $errorWebHookUrl ?? $generalWebHookUrl; } else { return $generalWebHookUrl; } } }