A free open source IT asset/license management system
adds google notifs to license seats check in and out
Godfrey M2406d2cfdb9b
diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.phpindex cc721f3ad6..c4c16f31ee 100644--- a/app/Notifications/CheckinAccessoryNotification.php+++ b/app/Notifications/CheckinAccessoryNotification.php@@ -160,7 +160,6 @@ class CheckinAccessoryNotification extends Notificationtrans('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)))diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.phpindex 2222f937f3..ba0621d078 100644--- a/app/Notifications/CheckinLicenseSeatNotification.php+++ b/app/Notifications/CheckinLicenseSeatNotification.php@@ -9,6 +9,11 @@ use Illuminate\Bus\Queueable;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;@@ -43,6 +48,10 @@ class CheckinLicenseSeatNotification extends Notification{$notifyBy = [];+ if (Setting::getSettings()->webhook_selected == 'google'){++ $notifyBy[] = GoogleChatChannel::class;+ }if (Setting::getSettings()->webhook_selected == 'microsoft'){$notifyBy[] = MicrosoftTeamsChannel::class;@@ -113,6 +122,34 @@ class CheckinLicenseSeatNotification extends Notification->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count())->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(+ '<strong>'.trans('mail.License_Checkin_Notification').'</strong>' ?: '',+ htmlspecialchars_decode($item->present()->name) ?: '',+ )+ ->section(+ Section::create(+ KeyValue::create(+ trans('mail.checkedin_from') ?: '',+ $target->present()->fullName() ?: '',+ trans('admin/consumables/general.remaining').': '.$item->availCount()->count(),+ )+ ->onClick(route('licenses.show', $item->id))+ )+ )+ );++ }+/*** Get the mail representation of the notification.diff --git a/app/Notifications/CheckoutLicenseSeatNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.phpindex d5c9871f3b..fcaa4761cb 100644--- a/app/Notifications/CheckoutLicenseSeatNotification.php+++ b/app/Notifications/CheckoutLicenseSeatNotification.php@@ -9,6 +9,11 @@ use Illuminate\Bus\Queueable;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;@@ -43,9 +48,12 @@ class CheckoutLicenseSeatNotification extends Notification*/public function via(){-$notifyBy = [];+ if (Setting::getSettings()->webhook_selected == 'google'){++ $notifyBy[] = GoogleChatChannel::class;+ }if (Setting::getSettings()->webhook_selected == 'microsoft'){$notifyBy[] = MicrosoftTeamsChannel::class;@@ -129,6 +137,33 @@ class CheckoutLicenseSeatNotification extends Notification->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count())->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(+ '<strong>'.trans('mail.License_Checkout_Notification').'</strong>' ?: '',+ htmlspecialchars_decode($item->present()->name) ?: '',+ )+ ->section(+ Section::create(+ KeyValue::create(+ trans('mail.assigned_to') ?: '',+ $target->present()->name ?: '',+ trans('admin/consumables/general.remaining').': '.$item->availCount()->count(),+ )+ ->onClick(route('users.show', $target->id))+ )+ )+ );++ }/*** Get the mail representation of the notification.diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.phpindex 418de5806f..759ff0f5e8 100644--- a/resources/lang/en-US/mail.php+++ b/resources/lang/en-US/mail.php@@ -42,6 +42,7 @@ return ['checkin_date' => 'Checkin Date:','checkout_date' => 'Checkout Date:','checkedout_from' => 'Checked out from',+ 'checkedin_from' => 'Checked in from','checked_into' => 'Checked into','click_on_the_link_accessory' => 'Please click on the link at the bottom to confirm that you have received the accessory.','click_on_the_link_asset' => 'Please click on the link at the bottom to confirm that you have received the asset.',