Beautiful Open-Source Form Builder
Better webhooks (#155)
formsdevec26c211d6c5
diff --git a/app/Listeners/FailedWebhookListener.php b/app/Listeners/FailedWebhookListener.phpnew file mode 100644index 000000000..c5c6f2028--- /dev/null+++ b/app/Listeners/FailedWebhookListener.php@@ -0,0 +1,38 @@+<?php++namespace App\Listeners;++use App\Notifications\Forms\FailedWebhookNotification;+use Illuminate\Contracts\Queue\ShouldQueue;+use Illuminate\Queue\InteractsWithQueue;+use Spatie\WebhookServer\Events\WebhookCallFailedEvent;++class FailedWebhookListener+{+ /**+ * Handle the event.+ *+ * @param object $event+ * @return void+ */+ public function handle(WebhookCallFailedEvent $event)+ {+ // Notify form owner+ if ($event->meta['type'] == 'form_submission') {+ $event->meta['form']->creator->notify(new FailedWebhookNotification($event));+ \Log::error('Failed form submission webhook', [+ 'webhook_url' => $event->webhookUrl,+ 'exception' => $event->errorType,+ 'message' => $event->errorMessage,+ 'form_id' => $event->meta['form']->id+ ]);+ return;+ }++ \Log::error('Failed webhook', [+ 'webhook_url' => $event->webhookUrl,+ 'exception' => $event->errorType,+ 'message' => $event->errorMessage+ ]);+ }+}diff --git a/app/Listeners/Forms/NotifyFormSubmission.php b/app/Listeners/Forms/NotifyFormSubmission.phpindex b8e59d73f..a2da167a0 100644--- a/app/Listeners/Forms/NotifyFormSubmission.php+++ b/app/Listeners/Forms/NotifyFormSubmission.php@@ -10,8 +10,8 @@ use Illuminate\Queue\InteractsWithQueue;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Notification;use App\Service\Forms\FormSubmissionFormatter;+use App\Service\Forms\Webhooks\WebhookHandlerProvider;use App\Notifications\Forms\FormSubmissionNotification;-use Vinkla\Hashids\Facades\Hashids;class NotifyFormSubmission implements ShouldQueue{@@ -25,165 +25,46 @@ class NotifyFormSubmission implements ShouldQueue*/public function handle(FormSubmitted $event){- if (!$event->form->is_pro) return;+ $this->sendEmailNotifications($event);- if ($event->form->notifies) {- // Send Email Notification- $subscribers = collect(preg_split("/\r\n|\n|\r/", $event->form->notification_emails))->filter(function($email) {- return filter_var($email, FILTER_VALIDATE_EMAIL);- });- \Log::debug('Sending email notification',[- 'recipients' => $subscribers->toArray(),- 'form_id' => $event->form->id,- 'form_slug' => $event->form->slug,- ]);- $subscribers->each(function ($subscriber) use ($event) {- Notification::route('mail', $subscriber)->notify(new FormSubmissionNotification($event));- });- }-- if ($event->form->notifies_slack) {- // Send Slack Notification- $this->sendSlackNotification($event);- }-- if ($event->form->notifies_discord) {- // Send Discord Notification- $this->sendDiscordNotification($event);+ $this->sendWebhookNotification($event, WebhookHandlerProvider::SIMPLE_WEBHOOK_PROVIDER);+ $this->sendWebhookNotification($event, WebhookHandlerProvider::SLACK_PROVIDER);+ $this->sendWebhookNotification($event, WebhookHandlerProvider::DISCORD_PROVIDER);+ foreach ($event->form->zappierHooks as $hook) {+ $hook->triggerHook($event->data);}--}-- private function sendSlackNotification(FormSubmitted $event)+ private function sendWebhookNotification(FormSubmitted $event, string $provider){- if($this->validateSlackWebhookUrl($event->form->slack_webhook_url)){- $submissionString = "";- $formatter = (new FormSubmissionFormatter($event->form, $event->data))->outputStringsOnly();- foreach ($formatter->getFieldsWithValue() as $field) {- $tmpVal = is_array($field['value']) ? implode(",", $field['value']) : $field['value'];- $submissionString .= ">*".ucfirst($field['name'])."*: ".$tmpVal." \n";- }-- $formURL = url("forms/".$event->form->slug);- $editFormURL = url("forms/".$event->form->slug."/show");- $submissionId = Hashids::encode($event->data['submission_id']);- $externalLinks = [- '*<'.$formURL.'|π Open Form>*',- '*<'.$editFormURL.'|βοΈ Edit Form>*'- ];- if($event->form->editable_submissions){- $externalLinks[] = '*<'.$event->form->share_url.'?submission_id='.$submissionId.'|βοΈ '.$event->form->editable_submissions_button_text.'>*';- }-- $finalSlackPostData = [- 'blocks' => [- [- 'type' => 'section',- 'text' => [- 'type' => 'mrkdwn',- 'text' => 'New submission for your form *<'.$formURL.'|'.$event->form->title.':>*',- ]- ],- [- 'type' => 'section',- 'text' => [- 'type' => 'mrkdwn',- 'text' => $submissionString- ]- ],- [- 'type' => 'section',- 'text' => [- 'type' => 'mrkdwn',- 'text' => implode(' ', $externalLinks),- ]- ],- ]- ];-- WebhookCall::create()- ->url($event->form->slack_webhook_url)- ->doNotSign()- ->payload($finalSlackPostData)- ->dispatch();- }- }-- private function validateSlackWebhookUrl($url)- {- return ($url) ? str_contains($url, 'https://hooks.slack.com/') : false;+ WebhookHandlerProvider::getProvider(+ $event->form,+ $event->data,+ $provider+ )->handle();}- private function sendDiscordNotification(FormSubmitted $event)+ /**+ * Sends an email to each email address in the form's notification_emails field+ * @param FormSubmitted $event+ * @return void+ */+ private function sendEmailNotifications(FormSubmitted $event){- if($this->validateDiscordWebhookUrl($event->form->discord_webhook_url)){- $submissionString = "";- $formatter = (new FormSubmissionFormatter($event->form, $event->data))->outputStringsOnly();-- foreach ($formatter->getFieldsWithValue() as $field) {- $tmpVal = is_array($field['value']) ? implode(",", $field['value']) : $field['value'];- $submissionString .= "**".ucfirst($field['name'])."**: `".$tmpVal."`\n";- }-- $form_name = $event->form->title;- $form = Form::find($event->form->id);- $formURL = url("forms/".$event->form->slug."/show/submissions");-- $finalDiscordPostData = [- "content" => "@here We have received a new submission for **$form_name**",- "username" => config('app.name'),- "avatar_url" => asset('img/logo.png'),- "tts" => false,- "embeds" => [- [- "title" => "π Go to $form_name",-- "type" => "rich",-- "description" => $submissionString,-- "url" => $formURL,-- "color" => hexdec(str_replace('#', '', $event->form->color)),+ if (!$event->form->is_pro || !$event->form->notifies) return;- "footer" => [- "text" => config('app.name'),- "icon_url" => asset('img/logo.png'),- ],-- "author" => [- "name" => config('app.name'),- "url" => config('app.url'),- ],-- "fields" => [- [- "name" => "Views π",- "value" => "$form->views_count",- "inline" => true- ],- [- "name" => "Submissions ποΈ",- "value" => "$form->submissions_count",- "inline" => true- ]- ]- ]- ]- ];-- WebhookCall::create()- ->url($event->form->discord_webhook_url)- ->doNotSign()- ->payload($finalDiscordPostData)- ->dispatch();- }- }-- private function validateDiscordWebhookUrl($url)- {- return ($url) ? str_contains($url, 'https://discord.com/api/webhooks') : false;+ $subscribers = collect(preg_split("/\r\n|\n|\r/", $event->form->notification_emails))->filter(function (+ ) {+ return filter_var($email, FILTER_VALIDATE_EMAIL);+ });+ \Log::debug('Sending email notification', [+ 'recipients' => $subscribers->toArray(),+ 'form_id' => $event->form->id,+ 'form_slug' => $event->form->slug,+ ]);+ $subscribers->each(function ($subscriber) use ($event) {+ Notification::route('mail', $subscriber)->notify(new FormSubmissionNotification($event));+ });}}diff --git a/app/Listeners/Forms/PostFormDataToWebhook.php b/app/Listeners/Forms/PostFormDataToWebhook.phpdeleted file mode 100644index 0ebd39539..000000000--- a/app/Listeners/Forms/PostFormDataToWebhook.php+++ /dev/null@@ -1,77 +0,0 @@-<?php--namespace App\Listeners\Forms;--use App\Events\Forms\FormSubmitted;-use App\Models\Forms\Form;-use Illuminate\Contracts\Queue\ShouldQueue;-use Illuminate\Queue\InteractsWithQueue;-use Spatie\WebhookServer\WebhookCall;-use App\Service\Forms\FormSubmissionFormatter;-use Vinkla\Hashids\Facades\Hashids;-class PostFormDataToWebhook implements ShouldQueue-{- use InteractsWithQueue;-- /**- * Handle the event.- *- * @param object $event- * @return void- */- public function handle(FormSubmitted $event)- {- $form = $event->form;- if (!$form->is_pro) return;- $data = $this->getWebhookData($event);-- $this->sendSimpleWebhook($form, $data);- $this->sendZappierWebhooks($form, $data);- }-- private function sendSimpleWebhook(Form $form, array $data) {- if ($form->webhook_url) {- \Log::debug('Sending data to webhook URL',[- 'webhook_url' => $form->webhook_url,- 'form_id' => $form->id,- 'form_slug' => $form->slug,- ]);- WebhookCall::create()- ->url($form->webhook_url)- ->doNotSign()- ->payload($data)- ->dispatch();- }- }-- private function sendZappierWebhooks(Form $form, array $data) {- foreach ($form->zappierHooks as $hook) {- \Log::debug('Sending data to Zapier webhook',[- 'form_id' => $form->id,- 'form_slug' => $form->slug,- ]);- $hook->triggerHook($data);- }- }-- private function getWebhookData(FormSubmitted $event): array {- $formatter = (new FormSubmissionFormatter($event->form, $event->data))->showHiddenFields();-- $formattedData = [];- foreach ($formatter->getFieldsWithValue() as $field) {- $formattedData[$field['name']] = $field['value'];- }-- $submissionId = Hashids::encode($event->data['submission_id']);- $data = [- 'form_title' => $event->form->title,- 'form_slug' => $event->form->slug,- 'submission' => $formattedData- ];- if($event->form->editable_submissions){- $data['edit_link'] = $event->form->share_url.'?submission_id='.$submissionId;- }-- return $data;- }-}diff --git a/app/Models/Forms/Form.php b/app/Models/Forms/Form.phpindex 9f061f444..c1458283c 100644--- a/app/Models/Forms/Form.php+++ b/app/Models/Forms/Form.php@@ -140,6 +140,11 @@ class Form extends Modelreturn url('/forms/'.$this->slug);}+ public function getEditUrlAttribute()+ {+ return url('/forms/'.$this->slug.'/show');+ }+public function getSubmissionsCountAttribute(){return $this->submissions()->count();diff --git a/app/Models/Integration/FormZapierWebhook.php b/app/Models/Integration/FormZapierWebhook.phpindex d8333e9fb..eb157c47e 100644--- a/app/Models/Integration/FormZapierWebhook.php+++ b/app/Models/Integration/FormZapierWebhook.php@@ -3,6 +3,7 @@namespace App\Models\Integration;use App\Models\Forms\Form;+use App\Service\Forms\Webhooks\WebhookHandlerProvider;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\SoftDeletes;@@ -27,11 +28,13 @@ class FormZapierWebhook extends Modelreturn $this->belongsTo(Form::class);}- public function triggerHook(array $data) {- WebhookCall::create()- ->url($this->hook_url)- ->doNotSign()- ->payload($data)- ->dispatch();+ public function triggerHook(array $data)+ {+ WebhookHandlerProvider::getProvider(+ $this->form,+ $data,+ WebhookHandlerProvider::ZAPIER_PROVIDER,+ $this->hook_url+ )->handle();}}diff --git a/app/Notifications/Forms/FailedWebhookNotification.php b/app/Notifications/Forms/FailedWebhookNotification.phpnew file mode 100644index 000000000..230985a07--- /dev/null+++ b/app/Notifications/Forms/FailedWebhookNotification.php@@ -0,0 +1,57 @@+<?php++namespace App\Notifications\Forms;++use App\Models\Forms\Form;+use Illuminate\Bus\Queueable;+use Illuminate\Notifications\Messages\MailMessage;+use Illuminate\Notifications\Notification;+use Illuminate\Support\Str;+use Spatie\WebhookServer\Events\WebhookCallFailedEvent;++class FailedWebhookNotification extends Notification+{+ use Queueable;++ public Form $form;+ public string $provider;++ /**+ * Create a new notification instance.+ *+ * @return void+ */+ public function __construct(protected WebhookCallFailedEvent $event)+ {+ $this->form = $this->event->meta['form'];+ $this->provider = $this->event->meta['provider'];+ }++ /**+ * Get the notification's delivery channels.+ *+ * @param mixed $notifiable+ * @return array+ */+ public function via($notifiable)+ {+ return ['mail'];+ }++ /**+ * Get the mail representation of the notification.+ *+ * @param mixed $notifiable+ * @return \Illuminate\Notifications\Messages\MailMessage+ */+ public function toMail($notifiable)+ {+ return (new MailMessage)+ ->subject("Notification issue with your NotionForm: '" . $this->form->title . "'")+ ->markdown('mail.form.webhook-error', [+ 'provider' => $this->provider,+ 'error' => $this->event->errorMessage,+ 'form' => $this->form,+ ]);+ }+}diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex af12900b0..164266cdb 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -4,16 +4,17 @@ namespace App\Providers;use App\Events\Forms\FormSubmitted;use App\Events\Models\FormCreated;+use App\Listeners\FailedWebhookListener;use App\Listeners\Auth\RegisteredListener;use App\Listeners\Forms\FormCreationConfirmation;use App\Listeners\Forms\NotifyFormSubmission;-use App\Listeners\Forms\PostFormDataToWebhook;use App\Listeners\Forms\SubmissionConfirmation;use App\Notifications\Forms\FormCreatedNotification;use Illuminate\Auth\Events\Registered;use Illuminate\Auth\Listeners\SendEmailVerificationNotification;use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;use Illuminate\Support\Facades\Event;+use Spatie\WebhookServer\Events\WebhookCallFailedEvent;class EventServiceProvider extends ServiceProvider{@@ -31,8 +32,10 @@ class EventServiceProvider extends ServiceProvider],FormSubmitted::class => [NotifyFormSubmission::class,- PostFormDataToWebhook::class,SubmissionConfirmation::class,+ ],+ WebhookCallFailedEvent::class => [+ FailedWebhookListener::class]];diff --git a/app/Service/Forms/FormCleaner.php b/app/Service/Forms/FormCleaner.phpindex 060305ddb..fc2889e10 100644--- a/app/Service/Forms/FormCleaner.php+++ b/app/Service/Forms/FormCleaner.php@@ -53,7 +53,7 @@ class FormCleaner'discord_webhook_url' => "Discord webhook disabled.",'editable_submissions' => 'Users will not be able to edit their submissions.','custom_code' => 'Custom code was disabled',- 'seo_meta' => 'Custom code was disabled',+ 'seo_meta' => 'Custom SEO was disabled',// For fields'file_upload' => "Link field is not a file upload.",diff --git a/app/Service/Forms/Webhooks/AbstractWebhookHandler.php b/app/Service/Forms/Webhooks/AbstractWebhookHandler.phpnew file mode 100644index 000000000..a76d84414--- /dev/null+++ b/app/Service/Forms/Webhooks/AbstractWebhookHandler.php@@ -0,0 +1,66 @@+<?php++namespace App\Service\Forms\Webhooks;++use App\Models\Forms\Form;+use App\Service\Forms\FormSubmissionFormatter;+use GuzzleHttp\Exception\ClientException;+use Illuminate\Support\Str;+use Spatie\WebhookServer\WebhookCall;+use Vinkla\Hashids\Facades\Hashids;++abstract class AbstractWebhookHandler+{+ public function __construct(protected Form $form, protected array $data)+ {+ }++ abstract protected function getProviderName(): ?string;++ abstract protected function getWebhookUrl(): ?string;++ /**+ * Default webhook payload. Can be changed in child classes.+ * @return array+ */+ protected function getWebhookData(): array+ {+ $formatter = (new FormSubmissionFormatter($this->form, $this->data))->showHiddenFields();++ $formattedData = [];+ foreach ($formatter->getFieldsWithValue() as $field) {+ $formattedData[$field['name']] = $field['value'];+ }++ $data = [+ 'form_title' => $this->form->title,+ 'form_slug' => $this->form->slug,+ 'submission' => $formattedData,+ ];+ if ($this->form->is_pro && $this->form->editable_submissions) {+ $data['edit_link'] = $this->form->share_url . '?submission_id=' . Hashids::encode($this->data['submission_id']);+ }++ return $data;+ }++ abstract protected function shouldRun(): bool;++ public function handle()+ {+ if (!$this->shouldRun()) return;++ WebhookCall::create()+ // Add context on error, used to notify form owner+ ->meta([+ 'type' => 'form_submission',+ 'data' => $this->data,+ 'form' => $this->form,+ 'provider' => $this->getProviderName(),+ ])+ ->url($this->getWebhookUrl())+ ->doNotSign()+ ->payload($this->getWebhookData())+ ->dispatchSync();+ }+}diff --git a/app/Service/Forms/Webhooks/DiscordHandler.php b/app/Service/Forms/Webhooks/DiscordHandler.phpnew file mode 100644index 000000000..446f21794--- /dev/null+++ b/app/Service/Forms/Webhooks/DiscordHandler.php@@ -0,0 +1,84 @@+<?php++namespace App\Service\Forms\Webhooks;++use App\Service\Forms\FormSubmissionFormatter;+use Illuminate\Support\Str;++class DiscordHandler extends AbstractWebhookHandler+{++ protected function getProviderName(): string+ {+ return 'Discord';+ }++ protected function getWebhookUrl(): ?string+ {+ return $this->form->discord_webhook_url;+ }++ protected function getWebhookData(): array+ {+ $submissionString = "";+ $formatter = (new FormSubmissionFormatter($this->form, $this->data))->outputStringsOnly();++ foreach ($formatter->getFieldsWithValue() as $field) {+ $tmpVal = is_array($field['value']) ? implode(",", $field['value']) : $field['value'];+ $submissionString .= "**" . ucfirst($field['name']) . "**: `" . $tmpVal . "`\n";+ }++ $form_name = $this->form->title;+ $formURL = url("forms/" . $this->form->slug . "/show/submissions");++ return [+ "content" => "@here We have received a new submission for **$form_name**",+ "username" => config('app.name'),+ "avatar_url" => asset('img/logo.png'),+ "tts" => false,+ "embeds" => [+ [+ "title" => "π Go to $form_name",++ "type" => "rich",++ "description" => $submissionString,++ "url" => $formURL,++ "color" => hexdec(str_replace('#', '', $this->form->color)),++ "footer" => [+ "text" => config('app.name'),+ "icon_url" => asset('img/logo.png'),+ ],++ "author" => [+ "name" => config('app.name'),+ "url" => config('app.url'),+ ],++ "fields" => [+ [+ "name" => "Views π",+ "value" => (string)$this->form->views_count,+ "inline" => true+ ],+ [+ "name" => "Submissions ποΈ",+ "value" => (string)$this->form->submissions_count,+ "inline" => true+ ]+ ]+ ]+ ]+ ];+ }++ protected function shouldRun(): bool+ {+ return !is_null($this->getWebhookUrl())+ && str_contains($this->getWebhookUrl(), 'https://discord.com/api/webhooks')+ && $this->form->is_pro;+ }+}diff --git a/app/Service/Forms/Webhooks/SimpleWebhookHandler.php b/app/Service/Forms/Webhooks/SimpleWebhookHandler.phpnew file mode 100644index 000000000..4d3add03b--- /dev/null+++ b/app/Service/Forms/Webhooks/SimpleWebhookHandler.php@@ -0,0 +1,24 @@+<?php++namespace App\Service\Forms\Webhooks;++use App\Service\Forms\FormSubmissionFormatter;+use Illuminate\Support\Str;++class SimpleWebhookHandler extends AbstractWebhookHandler+{+ protected function getProviderName(): string+ {+ return 'webhook';+ }++ protected function getWebhookUrl(): ?string+ {+ return $this->form->webhook_url;+ }++ protected function shouldRun(): bool+ {+ return !is_null($this->getWebhookUrl()) && $this->form->is_pro;+ }+}diff --git a/app/Service/Forms/Webhooks/SlackHandler.php b/app/Service/Forms/Webhooks/SlackHandler.phpnew file mode 100644index 000000000..2ed292db2--- /dev/null+++ b/app/Service/Forms/Webhooks/SlackHandler.php@@ -0,0 +1,75 @@+<?php++namespace App\Service\Forms\Webhooks;++use App\Service\Forms\FormSubmissionFormatter;+use Illuminate\Support\Str;+use Vinkla\Hashids\Facades\Hashids;++class SlackHandler extends AbstractWebhookHandler+{++ protected function getProviderName(): string+ {+ return 'Slack';+ }++ protected function getWebhookUrl(): ?string+ {+ return $this->form->slack_webhook_url;+ }++ protected function getWebhookData(): array+ {+ $submissionString = '';+ $formatter = (new FormSubmissionFormatter($this->form, $this->data))->outputStringsOnly();+ foreach ($formatter->getFieldsWithValue() as $field) {+ $tmpVal = is_array($field['value']) ? implode(',', $field['value']) : $field['value'];+ $submissionString .= '>*' . ucfirst($field['name']) . '*: ' . $tmpVal . " \n";+ }++ $formURL = url('forms/' . $this->form->slug);+ $editFormURL = url('forms/' . $this->form->slug . '/show');+ $submissionId = Hashids::encode($this->data['submission_id']);+ $externalLinks = [+ '*<' . $formURL . '|π Open Form>*',+ '*<' . $editFormURL . '|βοΈ Edit Form>*'+ ];+ if ($this->form->editable_submissions) {+ $externalLinks[] = '*<' . $this->form->share_url . '?submission_id=' . $submissionId . '|βοΈ ' . $this->form->editable_submissions_button_text . '>*';+ }++ return [+ 'blocks' => [+ [+ 'type' => 'section',+ 'text' => [+ 'type' => 'mrkdwn',+ 'text' => 'New submission for your form *<' . $formURL . '|' . $this->form->title . ':>*',+ ],+ ],+ [+ 'type' => 'section',+ 'text' => [+ 'type' => 'mrkdwn',+ 'text' => $submissionString,+ ],+ ],+ [+ 'type' => 'section',+ 'text' => [+ 'type' => 'mrkdwn',+ 'text' => implode(' ', $externalLinks),+ ],+ ],+ ],+ ];+ }++ protected function shouldRun(): bool+ {+ return !is_null($this->getWebhookUrl())+ && str_contains($this->getWebhookUrl(), 'https://hooks.slack.com/')+ && $this->form->is_pro;+ }+}diff --git a/app/Service/Forms/Webhooks/WebhookHandlerProvider.php b/app/Service/Forms/Webhooks/WebhookHandlerProvider.phpnew file mode 100644index 000000000..a271aa095--- /dev/null+++ b/app/Service/Forms/Webhooks/WebhookHandlerProvider.php@@ -0,0 +1,32 @@+<?php++namespace App\Service\Forms\Webhooks;++use App\Models\Forms\Form;++class WebhookHandlerProvider+{+ const SLACK_PROVIDER = 'slack';+ const DISCORD_PROVIDER = 'discord';+ const SIMPLE_WEBHOOK_PROVIDER = 'webhook';+ const ZAPIER_PROVIDER = 'zapier';++ public static function getProvider(Form $form, array $data, string $provider, ?string $webhookUrl = null)+ {+ switch ($provider) {+ case self::SLACK_PROVIDER:+ return new SlackHandler($form, $data);+ case self::DISCORD_PROVIDER:+ return new DiscordHandler($form, $data);+ case self::SIMPLE_WEBHOOK_PROVIDER:+ return new SimpleWebhookHandler($form, $data);+ case self::ZAPIER_PROVIDER:+ if (is_null($webhookUrl)) {+ throw new \Exception('Zapier webhook url is required');+ }+ return new ZapierHandler($form, $data, $webhookUrl);+ default:+ throw new \Exception('Unknown webhook provider');+ }+ }+}diff --git a/app/Service/Forms/Webhooks/ZapierHandler.php b/app/Service/Forms/Webhooks/ZapierHandler.phpnew file mode 100644index 000000000..e82c919d0--- /dev/null+++ b/app/Service/Forms/Webhooks/ZapierHandler.php@@ -0,0 +1,27 @@+<?php++namespace App\Service\Forms\Webhooks;++use App\Models\Forms\Form;++class ZapierHandler extends AbstractWebhookHandler+{+ public function __construct(protected Form $form, protected array $data, protected string $webhookUrl)+ {+ }++ protected function getProviderName(): ?string+ {+ return 'zapier';+ }++ protected function getWebhookUrl(): string+ {+ return $this->webhookUrl;+ }++ protected function shouldRun(): bool+ {+ return !is_null($this->getWebhookUrl());+ }+}diff --git a/resources/views/mail/form/webhook-error.blade.php b/resources/views/mail/form/webhook-error.blade.phpnew file mode 100644index 000000000..4df9a3164--- /dev/null+++ b/resources/views/mail/form/webhook-error.blade.php@@ -0,0 +1,15 @@+@component('mail::message')++Hello,++We tried to trigger a **{{$provider}}** notification for your form "{{$form->title}}", but it failed. Here is the error that we got:++@component('mail::panel')+{{$error}}+@endcomponent++Click [here to edit your form]({{$form->edit_url}}).++Contact us via the website live chat if you need any help.++@endcomponent