Better webhooks (#155)

* Enable Pro plan - WIP

* no pricing page if have no paid plans

* Set pricing ids in env

* views & submissions FREE for all

* extra param for env

* form password FREE for all

* Custom Code is PRO feature

* Replace codeinput prism with codemirror

* Better form Cleaning message

* Added risky user email spam protection

* fix form cleaning

* Custom SEO

* fix custom seo formcleaner

* Better webhooks

* fix test case
This commit is contained in:
formsdev
2023-08-30 16:07:08 +05:30
committed by GitHub
parent 01a01a8c72
commit ec26c211d6
15 changed files with 478 additions and 245 deletions

View File

@@ -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;
}
}