Skip to content

A free open source IT asset/license management system

added payload, new MS webhook test method

Godfrey M93ef8317e866
diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php
index 7fc53c7818..396dd5c08f 100644
--- a/app/Http/Livewire/SlackSettingsForm.php
+++ b/app/Http/Livewire/SlackSettingsForm.php
@@ -48,6 +48,12 @@ class SlackSettingsForm extends Component
"placeholder" => "",
"link" => "",
),
+ "ms_teams" => array(
+ "name" => trans('admin/settings/general.ms_teams'),
+ "icon" => "fa-brands fa-microsoft",
+ "placeholder" => "https://abcd.webhook.office.com/webhookb2/XXXXXXX",
+ "link" => "",
+ ),
];
$this->setting = Setting::getSettings();
@@ -178,4 +184,60 @@ class SlackSettingsForm extends Component
}
}
+ public function msTeamTestWebhook(){
+ $webhook = new Client([
+ 'base_url' => e($this->webhook_endpoint),
+ 'defaults' => [
+ 'exceptions' => false,
+ ],
+ 'allow_redirects' => false,
+ ]);
+
+ $payload = json_encode(
+ [
+ "@type"=> "MessageCard",
+ "@context"=> "http://schema.org/extensions",
+ "themeColor"=> "0076D7",
+ "summary"=> trans('mail.Asset_Checkin_Notification'),
+ "sections"=> [
+ "activityTitle"=> "Larry Bryant created a new task",
+ "activitySubtitle"=> "On Project Tango",
+ "activityImage"=> "https://adaptivecards.io/content/cats/3.png",
+ "facts"=> [
+ ["name"=> "Assigned to",
+ "value"=> "Unassigned"
+ ]
+ ,
+ ["name"=> "Due date",
+ "value"=> "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)"
+ ]
+ ,
+ ["name"=> "Status",
+ "value"=> "Not started"
+ ]
+ ],
+ "markdown"=> true
+ ]]
+ );
+ try {
+ $test = $webhook->post($this->webhook_endpoint, ['body' => $payload]);
+
+ if(($test->getStatusCode() == 302)||($test->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]));
+ }
+
+ return session()->flash('error' , trans('admin/settings/message.webhook.error_misc'));
+
+
+ }
}
diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php
index 05e56a9619..2154b42f4a 100644
--- a/app/Notifications/CheckinAssetNotification.php
+++ b/app/Notifications/CheckinAssetNotification.php
@@ -84,6 +84,46 @@ class CheckinAssetNotification extends Notification
->content($note);
});
}
+ public function toMsTeams()
+ {
+ $admin = $this->admin;
+ $item = $this->item;
+ $note = $this->note;
+
+ $fields = [
+ trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>',
+ trans('general.status') => $item->assetstatus->name,
+ trans('general.location') => ($item->location) ? $item->location->name : '',
+ ];
+
+ $payload = json_encode(
+ [
+ "@type"=> "MessageCard",
+ "@context"=> "http://schema.org/extensions",
+ "themeColor"=> "0076D7",
+ "summary"=> trans('mail.Asset_Checkin_Notification'),
+ "sections"=> [
+ "activityTitle"=> "Larry Bryant created a new task",
+ "activitySubtitle"=> "On Project Tango",
+ "activityImage"=> "https://adaptivecards.io/content/cats/3.png",
+ "facts"=> [
+ ["name"=> "Assigned to",
+ "value"=> "Unassigned"
+ ]
+ ,
+ ["name"=> "Due date",
+ "value"=> "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)"
+ ]
+ ,
+ ["name"=> "Status",
+ "value"=> "Not started"
+ ]
+ ],
+ "markdown"=> true
+ ]]
+ );
+
+ }
/**
* Get the mail representation of the notification.
diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php
index 0c67ca067e..50aa35f550 100644
--- a/resources/views/livewire/slack-settings-form.blade.php
+++ b/resources/views/livewire/slack-settings-form.blade.php
@@ -61,9 +61,9 @@
<div class="col-md-9 required" wire:ignore>
@if (Helper::isDemoMode())
- {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook')), 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'), 'ms_teams' => 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')), 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'), 'ms_teams' => 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
</div>
@@ -124,7 +124,11 @@
@if($webhook_endpoint != null && $webhook_channel != null)
<div class="form-group">
<div class="col-md-offset-2 col-md-9">
+ @if($webhook_selected == "ms_teams")
<a href="#" wire:click.prevent="testWebhook"
+ @else
+ <a href="#" wire:click.prevent="testWebhook"
+ @endif
class="btn btn-default btn-sm pull-left">
<i class="{{$webhook_icon}}" aria-hidden="true"></i>
{!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!}