diff --git a/app/Jobs/ProcessWebhook.php b/app/Jobs/ProcessWebhook.php index 7fae84546..12f53200a 100644 --- a/app/Jobs/ProcessWebhook.php +++ b/app/Jobs/ProcessWebhook.php @@ -34,7 +34,9 @@ class ProcessWebhook implements ShouldQueue $data = reset($data); } - $data = Arr::wrap(json_decode($data, true) ?? []); + if (is_string($data)) { + $data = Arr::wrap(json_decode($data, true) ?? []); + } $data['event'] = $this->webhookConfiguration->transformClassName($this->eventName); if ($this->webhookConfiguration->type === WebhookType::Discord) { @@ -55,12 +57,13 @@ class ProcessWebhook implements ShouldQueue } try { - $customHeaders = $this->webhookConfiguration->headers; $headers = []; - foreach ($customHeaders as $key => $value) { - $headers[$key] = $this->webhookConfiguration->replaceVars($data, $value); - } + if ($this->webhookConfiguration->type === WebhookType::Regular) { + foreach ($this->webhookConfiguration->headers as $key => $value) { + $headers[$key] = $this->webhookConfiguration->replaceVars($data, $value); + } + } Http::withHeaders($headers)->post($this->webhookConfiguration->endpoint, $data)->throw(); $successful = now(); } catch (Exception $exception) { diff --git a/app/Models/WebhookConfiguration.php b/app/Models/WebhookConfiguration.php index 31daa294a..60283f4d8 100644 --- a/app/Models/WebhookConfiguration.php +++ b/app/Models/WebhookConfiguration.php @@ -171,10 +171,14 @@ class WebhookConfiguration extends Model } /** - * @param array $replacement + * @param array|object $replacement * */ - public function replaceVars(array $replacement, string $subject): string + public function replaceVars(array|object $replacement, string $subject): string { + if (is_object($replacement)) { + $replacement = $replacement->toArray(); + } + return preg_replace_callback( '/{{(.*?)}}/', function ($matches) use ($replacement) {