Skip to content

Commit

Permalink
On slack,discord add support for Include hidden fields (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
chiragchhatrala authored Dec 30, 2024
1 parent 3d9bc60 commit 9a2d7b9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion api/app/Integrations/Handlers/DiscordIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static function getValidationRules(?Form $form): array
return [
'discord_webhook_url' => 'required|url|starts_with:https://discord.com/api/webhooks',
'include_submission_data' => 'boolean',
'include_hidden_fields_submission_data' => ['nullable', 'boolean'],
'link_open_form' => 'boolean',
'link_edit_form' => 'boolean',
'views_submissions_count' => 'boolean',
Expand All @@ -34,10 +35,14 @@ protected function shouldRun(): bool

protected function getWebhookData(): array
{
$settings = (array) $this->integrationData ?? [];

$formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
$formatter->showHiddenFields();
}
$formattedData = $formatter->getFieldsWithValue();

$settings = (array) $this->integrationData ?? [];
$externalLinks = [];
if (Arr::get($settings, 'link_open_form', true)) {
$externalLinks[] = '[**🔗 Open Form**](' . $this->form->share_url . ')';
Expand Down
7 changes: 6 additions & 1 deletion api/app/Integrations/Handlers/SlackIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static function getValidationRules(?Form $form): array
return [
'slack_webhook_url' => 'required|url|starts_with:https://hooks.slack.com/',
'include_submission_data' => 'boolean',
'include_hidden_fields_submission_data' => ['nullable', 'boolean'],
'link_open_form' => 'boolean',
'link_edit_form' => 'boolean',
'views_submissions_count' => 'boolean',
Expand All @@ -34,10 +35,14 @@ protected function shouldRun(): bool

protected function getWebhookData(): array
{
$settings = (array) $this->integrationData ?? [];

$formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
$formatter->showHiddenFields();
}
$formattedData = $formatter->getFieldsWithValue();

$settings = (array) $this->integrationData ?? [];
$externalLinks = [];
if (Arr::get($settings, 'link_open_form', true)) {
$externalLinks[] = '*<' . $this->form->share_url . '|🔗 Open Form>*';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
label="Include submission data"
help="With form submission answers"
/>
<toggle-switch-input
v-if="compVal.include_submission_data"
v-model="compVal.include_hidden_fields_submission_data"
name="include_hidden_fields_submission_data"
class="mt-4"
label="Include hidden fields"
help="If enabled then hidden fields will be included in the notification message"
/>
<toggle-switch-input
v-model="compVal.link_open_form"
name="link_open_form"
Expand Down Expand Up @@ -85,6 +93,7 @@ export default {
[
"message",
"include_submission_data",
'include_hidden_fields_submission_data',
"link_open_form",
"link_edit_form",
"views_submissions_count",
Expand All @@ -93,6 +102,8 @@ export default {
if (this.compVal[keyname] === undefined) {
if (keyname === 'message') {
this.compVal[keyname] = 'New form submission'
} else if (['include_hidden_fields_submission_data'].includes(keyname)) {
this.compVal[keyname] = false
} else {
this.compVal[keyname] = true
}
Expand Down

0 comments on commit 9a2d7b9

Please sign in to comment.