webhooks & slack changes (#90)

This commit is contained in:
Chirag Chhatrala 2023-02-19 17:42:13 +05:30 committed by GitHub
parent d6930d0dc2
commit eb3a11c992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -45,7 +45,7 @@ class StoreFormSubmissionJob implements ShouldQueue
$this->storeSubmission($formData); $this->storeSubmission($formData);
$formData["submission_id"] = $this->submissionData['submission_id'] ?? null; $formData["submission_id"] = $this->submissionId;
FormSubmitted::dispatch($this->form, $formData); FormSubmitted::dispatch($this->form, $formData);
} }

View File

@ -9,6 +9,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Spatie\WebhookServer\WebhookCall; use Spatie\WebhookServer\WebhookCall;
use App\Service\Forms\FormSubmissionFormatter; use App\Service\Forms\FormSubmissionFormatter;
use Vinkla\Hashids\Facades\Hashids;
class NotifyFormSubmission implements ShouldQueue class NotifyFormSubmission implements ShouldQueue
{ {
@ -57,6 +58,15 @@ class NotifyFormSubmission implements ShouldQueue
$formURL = url("forms/".$event->form->slug); $formURL = url("forms/".$event->form->slug);
$editFormURL = url("forms/".$event->form->slug."/show"); $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.'|✍️ Edit Submission>*';
}
$finalSlackPostData = [ $finalSlackPostData = [
'blocks' => [ 'blocks' => [
[ [
@ -77,7 +87,7 @@ class NotifyFormSubmission implements ShouldQueue
'type' => 'section', 'type' => 'section',
'text' => [ 'text' => [
'type' => 'mrkdwn', 'type' => 'mrkdwn',
'text' => '*<'.$formURL.'|🔗 Open Form>* *<'.$editFormURL.'|✍️ Edit Form>*', 'text' => implode(' ', $externalLinks),
] ]
], ],
] ]

View File

@ -8,7 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Spatie\WebhookServer\WebhookCall; use Spatie\WebhookServer\WebhookCall;
use App\Service\Forms\FormSubmissionFormatter; use App\Service\Forms\FormSubmissionFormatter;
use Vinkla\Hashids\Facades\Hashids;
class PostFormDataToWebhook implements ShouldQueue class PostFormDataToWebhook implements ShouldQueue
{ {
use InteractsWithQueue; use InteractsWithQueue;
@ -62,11 +62,16 @@ class PostFormDataToWebhook implements ShouldQueue
$formattedData[$field['name']] = $field['value']; $formattedData[$field['name']] = $field['value'];
} }
return [ $submissionId = Hashids::encode($event->data['submission_id']);
$data = [
'form_title' => $event->form->title, 'form_title' => $event->form->title,
'form_slug' => $event->form->slug, 'form_slug' => $event->form->slug,
'submission' => $formattedData 'submission' => $formattedData
]; ];
if($event->form->editable_submissions){
$data['edit_link'] = $event->form->share_url.'?submission_id='.$submissionId;
}
return $data;
} }
} }