mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-09 20:59:31 +01:00
Repair webhooks once again (#1815)
Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
This commit is contained in:
parent
0891db5342
commit
3c25b43b46
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user