Google Sheet - OAuth "client" powered integrations (#415)
* fix `helpers.php` * fix `.eslintrc.cjs` * spreadsheet manager * fetch providers. set `oauth_id` for integrations * create spreadsheet on integration create event * connect OAuth accounts * display actions. connect account if missing * cleanup * handle form field change * map integration data object to `SpreadsheetData` * validate request * wip * redirect to integrations page * fix refresh token * add helper text * add extra integration info * refactor * refresh google token * fix validation * add tests * Fix linting issue * Update composer lock file --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
46
app/Integrations/Handlers/EmailIntegration.php
Normal file
46
app/Integrations/Handlers/EmailIntegration.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Handlers;
|
||||
|
||||
use App\Rules\OneEmailPerLine;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use App\Notifications\Forms\FormSubmissionNotification;
|
||||
|
||||
class EmailIntegration extends AbstractIntegrationHandler
|
||||
{
|
||||
public static function getValidationRules(): array
|
||||
{
|
||||
return [
|
||||
'notification_emails' => ['required', new OneEmailPerLine()],
|
||||
'notification_reply_to' => 'email|nullable',
|
||||
];
|
||||
}
|
||||
|
||||
protected function shouldRun(): bool
|
||||
{
|
||||
return $this->integrationData->notification_emails && parent::shouldRun();
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (!$this->shouldRun()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$subscribers = collect(preg_split("/\r\n|\n|\r/", $this->integrationData->notification_emails))
|
||||
->filter(function ($email) {
|
||||
return filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
});
|
||||
Log::debug('Sending email notification', [
|
||||
'recipients' => $subscribers->toArray(),
|
||||
'form_id' => $this->form->id,
|
||||
'form_slug' => $this->form->slug,
|
||||
]);
|
||||
$subscribers->each(function ($subscriber) {
|
||||
Notification::route('mail', $subscriber)->notify(
|
||||
new FormSubmissionNotification($this->event, $this->integrationData)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user