Repair webhooks once again (#1815)

Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
This commit is contained in:
JoanFo 2025-11-09 15:35:00 +01:00 committed by GitHub
parent 0891db5342
commit 3c25b43b46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View File

@ -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) {

View File

@ -171,10 +171,14 @@ class WebhookConfiguration extends Model
}
/**
* @param array<mixed, mixed> $replacement
* @param array<mixed, mixed>|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) {