- $httpClient = new Client([
- 'timeout' => 3,
- 'allow_redirects' => ['strict' => true],
- ]);
-
- $request = new Request('POST', $this->webhook->endpoint, [
- 'Content-Type' => 'application/json'
- ], json_encode($this->buildWebhookData()));
-
- try {
- $response = $httpClient->send($request);
- if ($response->getStatusCode() >= 400) {
- Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with status {$response->getStatusCode()}");
- }
- } catch (ClientExceptionInterface $exception) {
- Log::error("Received error during webhook call to endpoint {$this->webhook->endpoint}: {$exception->getMessage()}");
+ $themeResponse = Theme::dispatch(ThemeEvents::WEBHOOK_CALL_BEFORE, $this->event, $this->webhook, $this->detail);
+ $webhookData = $themeResponse ?? $this->buildWebhookData();
+
+ $response = Http::asJson()
+ ->withOptions(['allow_redirects' => ['strict' => true]])
+ ->timeout(3)
+ ->post($this->webhook->endpoint, $webhookData);
+
+ if ($response->failed()) {
+ Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with status {$response->status()}");