From e969f8808c8bf65337b7e958b52ae3b3f153b80c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 23 Jan 2024 11:10:04 -0800 Subject: [PATCH] adds licenses ms notifications --- app/Listeners/CheckoutableListener.php | 10 ++++--- .../CheckinAccessoryNotification.php | 4 +-- .../CheckinLicenseSeatNotification.php | 26 ++++++++++++++++++ .../CheckoutAccessoryNotification.php | 1 - .../CheckoutLicenseSeatNotification.php | 27 +++++++++++++++++++ resources/lang/en-US/mail.php | 1 + 6 files changed, 63 insertions(+), 6 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 0fcbb902d7..ea1a4f036e 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -112,11 +112,15 @@ class CheckoutableListener $this->getCheckinNotification($event) ); } + //slack doesn't include the url in its messaging format so this is needed to hit the endpoint + if(Setting::getSettings()->webhook_selected =='slack') { - if ($this->shouldSendWebhookNotification()) { - Notification::route('slack', Setting::getSettings()->webhook_endpoint) - ->notify($this->getCheckinNotification($event)); + if ($this->shouldSendWebhookNotification()) { + Notification::route('slack', Setting::getSettings()->webhook_endpoint) + ->notify($this->getCheckinNotification($event)); + } } + } catch (ClientException $e) { Log::debug("Exception caught during checkout notification: " . $e->getMessage()); } catch (Exception $e) { diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index f3ec95827d..83a01df410 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -123,10 +123,10 @@ class CheckinAccessoryNotification extends Notification ->to($this->settings->webhook_endpoint) ->type('success') ->addStartGroupToSection('activityTitle') - ->title("Accessory Checked Out") + ->title("Accessory Checked In") ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact('Checked out from ', $item->location->name) + ->fact('Checked into ', $item->location->name) ->fact(trans('mail.Accessory_Checkin_Notification')." by ", $admin->present()->fullName()) ->fact('Number Remaining', $item->numRemaining()) ->fact('Notes', $note ?: 'No notes'); diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php index 2c7fe2fd85..d05f5ef6c1 100644 --- a/app/Notifications/CheckinLicenseSeatNotification.php +++ b/app/Notifications/CheckinLicenseSeatNotification.php @@ -9,6 +9,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckinLicenseSeatNotification extends Notification { @@ -41,6 +43,11 @@ class CheckinLicenseSeatNotification extends Notification { $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + $notifyBy[] = MicrosoftTeamsChannel::class; + } + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -87,6 +94,25 @@ class CheckinLicenseSeatNotification extends Notification ->content($note); }); } + public function toMicrosoftTeams() + { + $target = $this->target; + $admin = $this->admin; + $item = $this->item; + $note = $this->note; + + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->addStartGroupToSection('activityTitle') + ->title("License Checked in") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'header') + ->fact(trans('mail.License_Checkin_Notification')." by ", $admin->present()->fullName() ?: 'ClI tool') + ->fact('Checked in from', $target->present()->fullName()) + ->fact('Seats Remaining', $item->availCount()->count()) + ->fact('Notes', $note ?: 'No notes'); + } /** * Get the mail representation of the notification. diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index 33aaf41b16..33bed0db60 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -26,7 +26,6 @@ class CheckoutAccessoryNotification extends Notification $this->note = $note; $this->target = $checkedOutTo; $this->acceptance = $acceptance; - $this->settings = Setting::getSettings(); } diff --git a/app/Notifications/CheckoutLicenseSeatNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.php index 2dd6480a30..9a7861444c 100644 --- a/app/Notifications/CheckoutLicenseSeatNotification.php +++ b/app/Notifications/CheckoutLicenseSeatNotification.php @@ -9,6 +9,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckoutLicenseSeatNotification extends Notification { @@ -41,8 +43,14 @@ class CheckoutLicenseSeatNotification extends Notification */ public function via() { + $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + $notifyBy[] = MicrosoftTeamsChannel::class; + } + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -102,6 +110,25 @@ class CheckoutLicenseSeatNotification extends Notification ->content($note); }); } + public function toMicrosoftTeams() + { + $target = $this->target; + $admin = $this->admin; + $item = $this->item; + $note = $this->note; + + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->addStartGroupToSection('activityTitle') + ->title("License Checked Out") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') + ->fact(trans('mail.License_Checkout_Notification')." by ", $admin->present()->fullName()) + ->fact('Checked out to', $target->present()->fullName()) + ->fact('Seats Remaining', $item->availCount()->count()) + ->fact('Notes', $note ?: 'No notes'); + } /** * Get the mail representation of the notification. diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index c722a423a9..a3632400c4 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -21,6 +21,7 @@ return [ 'Item_Request_Canceled' => 'Item Request Canceled', 'Item_Requested' => 'Item Requested', 'License_Checkin_Notification' => 'License checked in', + 'License_Checkout_Notification' => 'License checked out', 'Low_Inventory_Report' => 'Low Inventory Report', 'a_user_canceled' => 'A user has canceled an item request on the website', 'a_user_requested' => 'A user has requested an item on the website',