- $response = Http::asJson()
- ->withOptions(['allow_redirects' => ['strict' => true]])
- ->timeout(3)
- ->post($this->webhook->endpoint, $this->buildWebhookData());
-
- if ($response->failed()) {
- Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with status {$response->status()}");
- }
- }
-
- protected function buildWebhookData(): array
- {
- $textParts = [
- $this->initiator->name,
- trans('activities.' . $this->event),
- ];
-
- if ($this->detail instanceof Entity) {
- $textParts[] = '"' . $this->detail->name . '"';
+ $themeResponse = Theme::dispatch(ThemeEvents::WEBHOOK_CALL_BEFORE, $this->event, $this->webhook, $this->detail, $this->initiator, $this->initiatedTime);
+ $webhookData = $themeResponse ?? WebhookFormatter::getDefault($this->event, $this->webhook, $this->detail, $this->initiator, $this->initiatedTime)->format();
+ $lastError = null;
+
+ try {
+ $response = Http::asJson()
+ ->withOptions(['allow_redirects' => ['strict' => true]])
+ ->timeout($this->webhook->timeout)
+ ->post($this->webhook->endpoint, $webhookData);
+ } catch (\Exception $exception) {
+ $lastError = $exception->getMessage();
+ Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with error \"{$lastError}\"");