diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php index 376c70fdea..4b4fcc6ac6 100644 --- a/app/Notifications/CheckoutConsumableNotification.php +++ b/app/Notifications/CheckoutConsumableNotification.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 CheckoutConsumableNotification extends Notification { @@ -43,6 +45,11 @@ class CheckoutConsumableNotification extends Notification { $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + $notifyBy[] = MicrosoftTeamsChannel::class; + } + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -102,6 +109,25 @@ class CheckoutConsumableNotification 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("Consumable Checked Out") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') + ->fact(trans('mail.Consumable_checkout_notification')." by ", $admin->present()->fullName()) + ->fact('Checked out to', $target->present()->fullName()) + ->fact('Number Remaining', $item->numRemaining()) + ->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 a3632400c4..ca323c76c6 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -12,6 +12,7 @@ return [ 'Confirm_asset_delivery' => 'Asset delivery confirmation', 'Confirm_consumable_delivery' => 'Consumable delivery confirmation', 'Confirm_license_delivery' => 'License delivery confirmation', + 'Consumable_checkout_notification' => 'Consumable checked out', 'Days' => 'Days', 'Expected_Checkin_Date' => 'An asset checked out to you is due to be checked back in on :date', 'Expected_Checkin_Notification' => 'Reminder: :name checkin deadline approaching',