diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index ee63e7a48f..101583f582 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -42,18 +42,28 @@ class SlackSettingsForm extends Component "icon" => 'fab fa-slack', "placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX", "link" => 'https://api.slack.com/messaging/webhooks', + "test" => "testWebhook" ), "general"=> array( "name" => trans('admin/settings/general.general_webhook'), "icon" => "fab fa-hashtag", "placeholder" => trans('general.url'), "link" => "", + "test" => "testWebhook" + ), + "google" => array( + "name" => trans('admin/settings/general.google_workspaces'), + "icon" => "fa-brands fa-google", + "placeholder" => "https://chat.googleapis.com/v1/spaces/xxxxxxxx/messages?key=xxxxxx", + "link" => "https://developers.google.com/chat/how-tos/webhooks#register_the_incoming_webhook", + "test" => "googleWebhookTest" ), "microsoft" => array( "name" => trans('admin/settings/general.ms_teams'), "icon" => "fa-brands fa-microsoft", "placeholder" => "https://abcd.webhook.office.com/webhookb2/XXXXXXX", "link" => "https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet#create-incoming-webhooks-1", + "test" => "msTeamTestWebhook" ), ]; @@ -64,6 +74,7 @@ class SlackSettingsForm extends Component $this->webhook_icon = $this->webhook_text[$this->setting->webhook_selected]["icon"]; $this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"]; $this->webhook_link = $this->webhook_text[$this->setting->webhook_selected]["link"]; + $this->webhook_test = $this->webhook_text[$this->setting->webhook_selected]["test"]; $this->webhook_endpoint = $this->setting->webhook_endpoint; $this->webhook_channel = $this->setting->webhook_channel; $this->webhook_botname = $this->setting->webhook_botname; @@ -87,11 +98,11 @@ class SlackSettingsForm extends Component $this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"]; $this->webhook_endpoint = null; $this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"]; + $this->webhook_test = $this->webhook_text[$this->webhook_selected]["test"]; if($this->webhook_selected != 'slack'){ $this->isDisabled= ''; $this->save_button = trans('general.save'); } - } private function isButtonDisabled() { @@ -188,7 +199,35 @@ class SlackSettingsForm extends Component } } - public function msTeamTestWebhook(){ + public function googleWebhookTest(){ + + $payload = [ + "text" => trans('general.webhook_test_msg', ['app' => $this->webhook_name]), + ]; + + try { + $response = Http::withHeaders([ + 'content-type' => 'applications/json', + ])->post($this->webhook_endpoint, + $payload)->throw(); + + + if (($response->getStatusCode() == 302) || ($response->getStatusCode() == 301)) { + return session()->flash('error', trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint])); + } + + $this->isDisabled=''; + $this->save_button = trans('general.save'); + return session()->flash('success' , trans('admin/settings/message.webhook.success', ['webhook_name' => $this->webhook_name])); + + } catch (\Exception $e) { + + $this->isDisabled='disabled'; + $this->save_button = trans('admin/settings/general.webhook_presave'); + return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name])); + } + } + public function msTeamTestWebhook(){ $payload = [ diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php index 21e5759053..0c572e0676 100644 --- a/resources/lang/en-US/admin/settings/general.php +++ b/resources/lang/en-US/admin/settings/general.php @@ -70,6 +70,7 @@ return [ 'general_settings_keywords' => 'company support, signature, acceptance, email format, username format, images, per page, thumbnail, eula, tos, dashboard, privacy', 'general_settings_help' => 'Default EULA and more', 'generate_backup' => 'Generate Backup', + 'google_workspaces' => 'Google Workspaces', 'header_color' => 'Header Color', 'info' => 'These settings let you customize certain aspects of your installation.', 'label_logo' => 'Label Logo', diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index ad3271bbc7..8182647098 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -61,9 +61,9 @@
@if (Helper::isDemoMode()) - {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'microsoft' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:100%', 'disabled')) }} + {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'),'google' => trans('admin/settings/general.google_workspaces'), 'microsoft' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:100%', 'disabled')) }} @else - {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'microsoft' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'data-minimum-results-for-search' => '-1', 'style'=>'width:100%')) }} + {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'),'google' => trans('admin/settings/general.google_workspaces'), 'microsoft' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'data-minimum-results-for-search' => '-1', 'style'=>'width:100%')) }} @endif
@@ -90,23 +90,25 @@ -
-
- {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }} -
-
- + @if($webhook_selected != 'microsoft' && $webhook_selected!= 'google') +
+
+ {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }} +
+
+ - {!! $errors->first('webhook_channel', '') !!} + {!! $errors->first('webhook_channel', '') !!} +
-
+ @endif @if (Helper::isDemoMode()) @include('partials.forms.demo-mode') @endif - @if($webhook_selected != 'microsoft') + @if($webhook_selected != 'microsoft' && $webhook_selected != 'google')
{{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }} @@ -122,14 +124,11 @@ @endif + @if($webhook_endpoint != null && $webhook_channel != null)