diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index f376c26a8469..cc721f3ad602 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -9,6 +9,11 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\GoogleChat\Card; +use NotificationChannels\GoogleChat\GoogleChatChannel; +use NotificationChannels\GoogleChat\GoogleChatMessage; +use NotificationChannels\GoogleChat\Section; +use NotificationChannels\GoogleChat\Widgets\KeyValue; use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; @@ -38,6 +43,10 @@ public function __construct(Accessory $accessory, $checkedOutTo, User $checkedIn public function via() { $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'google'){ + + $notifyBy[] = GoogleChatChannel::class; + } if (Setting::getSettings()->webhook_selected == 'microsoft'){ @@ -132,6 +141,33 @@ public function toMicrosoftTeams() ->fact(trans('admin/consumables/general.remaining'), $item->numRemaining()) ->fact(trans('mail.notes'), $note ?: ''); } + public function toGoogleChat() + { + $item = $this->item; + $note = $this->note; + + return GoogleChatMessage::create() + ->to($this->settings->webhook_endpoint) + ->card( + Card::create() + ->header( + ''.trans('mail.Accessory_Checkin_Notification').'' ?: '', + htmlspecialchars_decode($item->present()->name) ?: '', + ) + ->section( + Section::create( + KeyValue::create( + trans('mail.checked_into').': '.$item->location->name ? $item->location->name : '', + trans('admin/consumables/general.remaining').': '.$item->numRemaining(), + trans('admin/hardware/form.notes').": ".$note ?: '', + + ) + ->onClick(route('accessories.show', $item->id)) + ) + ) + ); + + } /** * Get the mail representation of the notification. diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index d0e34bc87ff6..71632ca0e01a 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -136,7 +136,7 @@ public function toGoogleChat() KeyValue::create( trans('mail.checked_into') ?: '', $item->location->name ? $item->location->name : '', - trans('admin/hardware/form.status').":".$item->assetstatus->name, + trans('admin/hardware/form.status').": ".$item->assetstatus->name, ) ->onClick(route('hardware.show', $item->id)) ) diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index 62fce8e176e7..868b1ced46a1 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -9,6 +9,11 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\GoogleChat\Card; +use NotificationChannels\GoogleChat\GoogleChatChannel; +use NotificationChannels\GoogleChat\GoogleChatMessage; +use NotificationChannels\GoogleChat\Section; +use NotificationChannels\GoogleChat\Widgets\KeyValue; use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; @@ -37,6 +42,10 @@ public function __construct(Accessory $accessory, $checkedOutTo, User $checkedOu public function via() { $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'google'){ + + $notifyBy[] = GoogleChatChannel::class; + } if (Setting::getSettings()->webhook_selected == 'microsoft'){ @@ -123,6 +132,34 @@ public function toMicrosoftTeams() ->fact(trans('mail.notes'), $note ?: ''); } + public function toGoogleChat() + { + $target = $this->target; + $item = $this->item; + $note = $this->note; + + return GoogleChatMessage::create() + ->to($this->settings->webhook_endpoint) + ->card( + Card::create() + ->header( + ''.trans('mail.Accessory_Checkout_Notification').'' ?: '', + htmlspecialchars_decode($item->present()->name) ?: '', + ) + ->section( + Section::create( + KeyValue::create( + trans('mail.assigned_to') ?: '', + $target->present()->name ?: '', + trans('admin/consumables/general.remaining').": ". $item->numRemaining(), + ) + ->onClick(route('users.show', $target->id)) + ) + ) + ); + + } + /** * Get the mail representation of the notification.