fixed integration link, added some conditionals

This commit is contained in:
Godfrey M 2024-01-17 16:30:27 -08:00
parent 9f2af40ef2
commit ce02e43ab2
3 changed files with 58 additions and 63 deletions

View file

@ -46,23 +46,24 @@ class SlackSettingsForm extends Component
"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" => "", "placeholder" => "Insert URL",
"link" => "", "link" => "",
), ),
"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" => "", "link" => "https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet#create-incoming-webhooks-1",
), ),
]; ];
$this->setting = Setting::getSettings(); $this->setting = Setting::getSettings();
$this->save_button = trans('general.save'); $this->save_button = trans('general.save');
$this->webhook_selected = $this->setting->webhook_selected; $this->webhook_selected = $this->setting->webhook_selected;
$this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"];
$this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"]; $this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"];
$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_link = $this->webhook_text[$this->setting->webhook_selected]["link"];
$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;
@ -90,6 +91,7 @@ class SlackSettingsForm extends Component
$this->isDisabled= ''; $this->isDisabled= '';
$this->save_button = trans('general.save'); $this->save_button = trans('general.save');
} }
} }
private function isButtonDisabled() { private function isButtonDisabled() {
@ -182,44 +184,40 @@ class SlackSettingsForm extends Component
$this->setting->save(); $this->setting->save();
session()->flash('success',trans('admin/settings/message.update.success')); session()->flash('success',trans('admin/settings/message.update.success'));
} }
} }
public function msTeamTestWebhook(){ public function msTeamTestWebhook(){
$payload = $payload =
[ [
"@type" => "MessageCard", "@type" => "MessageCard",
"@context" => "http://schema.org/extensions", "@context" => "http://schema.org/extensions",
"summary" => "Announcement Summary", "summary" => "Snipe-IT Integration Test Summary",
"title" => "Snipe-IT Integration Test", "title" => "Snipe-IT Integration Test",
'text' => trans('general.webhook_test_msg', ['app' => $this->webhook_name]), "text" => trans('general.webhook_test_msg', ['app' => $this->webhook_name]),
]; ];
try { try {
$response = Http::withHeaders([ $response = Http::withHeaders([
'content-type' => 'applications/json', 'content-type' => 'applications/json',
])->post($this->webhook_endpoint, ])->post($this->webhook_endpoint,
$payload)->throw(); $payload)->throw();
if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){
if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){ return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint]));
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]));
} }
$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]));
}
return session()->flash('error' , trans('admin/settings/message.webhook.error_misc')); return session()->flash('error' , trans('admin/settings/message.webhook.error_misc'));
} }
} }

View file

@ -97,30 +97,26 @@ class CheckinAssetNotification extends Notification
]; ];
$payload = json_encode( $payload = json_encode(
[ [
"@type"=> "MessageCard", "type" => "message",
"@context"=> "http://schema.org/extensions", "attachments" => [
"themeColor"=> "0076D7", [
"summary"=> trans('mail.Asset_Checkin_Notification'), "contentType" => "application/vnd.microsoft.card.adaptive",
"sections"=> [ "contentUrl" => null,
"activityTitle"=> "Larry Bryant created a new task", "content" => [
"activitySubtitle"=> "On Project Tango", "schema" => "http://adaptivecards.io/schemas/adaptive-card.json",
"activityImage"=> "https://adaptivecards.io/content/cats/3.png", "type" => "AdaptiveCard",
"facts"=> [ "version" => "1.2",
["name"=> "Assigned to", "body" => [
"value"=> "Unassigned" [
"type" => "TextBlock",
"text" => "For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)"
]
]
]
] ]
, ]
["name"=> "Due date", ]
"value"=> "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)"
]
,
["name"=> "Status",
"value"=> "Not started"
]
],
"markdown"=> true
]]
); );
} }

View file

@ -106,16 +106,17 @@
@endif @endif
<!-- Webhook botname --> <!-- Webhook botname -->
<div class="form-group{{ $errors->has('webhook_botname') ? ' error' : '' }}"> @if($webhook_selected != 'microsoft')
<div class="col-md-2"> <div class="form-group{{ $errors->has('webhook_botname') ? ' error' : '' }}">
{{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }} <div class="col-md-2">
{{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
</div>
<div class="col-md-9">
<input type="text" wire:model.lazy="webhook_botname" class='form-control' placeholder="Snipe-Bot" {{ old('webhook_botname', $webhook_botname)}}{{ Helper::isDemoMode() ? ' disabled' : ''}}>
{!! $errors->first('webhook_botname', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div><!--col-md-10-->
</div> </div>
<div class="col-md-9"> @endif
<input type="text" wire:model.lazy="webhook_botname" class='form-control' placeholder="Snipe-Bot" {{ old('webhook_botname', $webhook_botname)}}{{ Helper::isDemoMode() ? ' disabled' : ''}}>
{!! $errors->first('webhook_botname', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div><!--col-md-10-->
</div>
@if (!Helper::isDemoMode()) @if (!Helper::isDemoMode())
@include('partials.forms.demo-mode') @include('partials.forms.demo-mode')
@endif @endif