webhook test works

This commit is contained in:
Godfrey M 2024-01-29 12:58:09 -08:00
parent 30c2927987
commit dfa33f651a
3 changed files with 57 additions and 18 deletions

View file

@ -42,18 +42,28 @@ class SlackSettingsForm extends Component
"icon" => 'fab fa-slack', "icon" => 'fab fa-slack',
"placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX", "placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",
"link" => 'https://api.slack.com/messaging/webhooks', "link" => 'https://api.slack.com/messaging/webhooks',
"test" => "testWebhook"
), ),
"general"=> array( "general"=> array(
"name" => trans('admin/settings/general.general_webhook'), "name" => trans('admin/settings/general.general_webhook'),
"icon" => "fab fa-hashtag", "icon" => "fab fa-hashtag",
"placeholder" => trans('general.url'), "placeholder" => trans('general.url'),
"link" => "", "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( "microsoft" => array(
"name" => trans('admin/settings/general.ms_teams'), "name" => trans('admin/settings/general.ms_teams'),
"icon" => "fa-brands fa-microsoft", "icon" => "fa-brands fa-microsoft",
"placeholder" => "https://abcd.webhook.office.com/webhookb2/XXXXXXX", "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", "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_icon = $this->webhook_text[$this->setting->webhook_selected]["icon"];
$this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"]; $this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"];
$this->webhook_link = $this->webhook_text[$this->setting->webhook_selected]["link"]; $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_endpoint = $this->setting->webhook_endpoint;
$this->webhook_channel = $this->setting->webhook_channel; $this->webhook_channel = $this->setting->webhook_channel;
$this->webhook_botname = $this->setting->webhook_botname; $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_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"];
$this->webhook_endpoint = null; $this->webhook_endpoint = null;
$this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"]; $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'){ if($this->webhook_selected != 'slack'){
$this->isDisabled= ''; $this->isDisabled= '';
$this->save_button = trans('general.save'); $this->save_button = trans('general.save');
} }
} }
private function isButtonDisabled() { 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 = $payload =
[ [

View file

@ -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_keywords' => 'company support, signature, acceptance, email format, username format, images, per page, thumbnail, eula, tos, dashboard, privacy',
'general_settings_help' => 'Default EULA and more', 'general_settings_help' => 'Default EULA and more',
'generate_backup' => 'Generate Backup', 'generate_backup' => 'Generate Backup',
'google_workspaces' => 'Google Workspaces',
'header_color' => 'Header Color', 'header_color' => 'Header Color',
'info' => 'These settings let you customize certain aspects of your installation.', 'info' => 'These settings let you customize certain aspects of your installation.',
'label_logo' => 'Label Logo', 'label_logo' => 'Label Logo',

View file

@ -61,9 +61,9 @@
<div class="col-md-9 required" wire:ignore> <div class="col-md-9 required" wire:ignore>
@if (Helper::isDemoMode()) @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 @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 @endif
</div> </div>
@ -90,23 +90,25 @@
<!-- Webhook channel --> <!-- Webhook channel -->
<div class="form-group{{ $errors->has('webhook_channel') ? ' error' : '' }}"> @if($webhook_selected != 'microsoft' && $webhook_selected!= 'google')
<div class="col-md-2"> <div class="form-group{{ $errors->has('webhook_channel') ? ' error' : '' }}">
{{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }} <div class="col-md-2">
</div> {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }}
<div class="col-md-9 required"> </div>
<input type="text" wire:model.lazy="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}"{{ Helper::isDemoMode() ? ' disabled' : ''}}> <div class="col-md-9 required">
<input type="text" wire:model.lazy="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>
{!! $errors->first('webhook_channel', '<span class="alert-msg" aria-hidden="true">:message</span>') !!} {!! $errors->first('webhook_channel', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div> </div>
</div> @endif
@if (Helper::isDemoMode()) @if (Helper::isDemoMode())
@include('partials.forms.demo-mode') @include('partials.forms.demo-mode')
@endif @endif
<!-- Webhook botname --> <!-- Webhook botname -->
@if($webhook_selected != 'microsoft') @if($webhook_selected != 'microsoft' && $webhook_selected != 'google')
<div class="form-group{{ $errors->has('webhook_botname') ? ' error' : '' }}"> <div class="form-group{{ $errors->has('webhook_botname') ? ' error' : '' }}">
<div class="col-md-2"> <div class="col-md-2">
{{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }} {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
@ -122,14 +124,11 @@
@endif @endif
<!--Webhook Integration Test--> <!--Webhook Integration Test-->
@if($webhook_endpoint != null && $webhook_channel != null) @if($webhook_endpoint != null && $webhook_channel != null)
<div class="form-group"> <div class="form-group">
<div class="col-md-offset-2 col-md-9"> <div class="col-md-offset-2 col-md-9">
@if($webhook_selected == "microsoft") <a href="#" wire:click.prevent="{{$webhook_test}}"
<a href="#" wire:click.prevent="msTeamTestWebhook"
@else
<a href="#" wire:click.prevent="testWebhook"
@endif
class="btn btn-default btn-sm pull-left"> class="btn btn-default btn-sm pull-left">
<i class="{{$webhook_icon}}" aria-hidden="true"></i> <i class="{{$webhook_icon}}" aria-hidden="true"></i>
{!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!} {!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!}