A free open source IT asset/license management system
adds google notifs for asset check in and out
Godfrey M87bce0c097a9
diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.phpindex 101583f582..e2f1b4ef14 100644--- a/app/Http/Livewire/SlackSettingsForm.php+++ b/app/Http/Livewire/SlackSettingsForm.php@@ -37,11 +37,11 @@ class SlackSettingsForm extends Componentpublic function mount() {$this->webhook_text= [- "slack" => array(+ "slack" => array("name" => trans('admin/settings/general.slack') ,- "icon" => 'fab fa-slack',- "placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",- "link" => 'https://api.slack.com/messaging/webhooks',+ "icon" => 'fab fa-slack',+ "placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",+ "link" => 'https://api.slack.com/messaging/webhooks',"test" => "testWebhook"),"general"=> array(diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.phpindex 162b07d276..86a0957839 100644--- a/app/Listeners/CheckoutableListener.php+++ b/app/Listeners/CheckoutableListener.php@@ -60,7 +60,7 @@ class CheckoutableListenerif ($this->shouldSendWebhookNotification()) {//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(Setting::getSettings()->webhook_selected =='slack' || Setting::getSettings()->webhook_selected =='general') {Notification::route('slack', Setting::getSettings()->webhook_endpoint)->notify($this->getCheckoutNotification($event));diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.phpindex 8e9467c54f..d0e34bc87f 100644--- a/app/Notifications/CheckinAssetNotification.php+++ b/app/Notifications/CheckinAssetNotification.php@@ -10,6 +10,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;@@ -46,6 +51,10 @@ class CheckinAssetNotification extends Notificationpublic function via(){$notifyBy = [];+ if (Setting::getSettings()->webhook_selected == 'google'){++ $notifyBy[] = GoogleChatChannel::class;+ }if (Setting::getSettings()->webhook_selected == 'microsoft'){@@ -108,6 +117,33 @@ class CheckinAssetNotification extends Notification->fact(trans('admin/hardware/form.status'), $item->assetstatus->name)->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.Asset_Checkin_Notification').'</strong>' ?: '',+ htmlspecialchars_decode($item->present()->name) ?: '',+ )+ ->section(+ Section::create(+ KeyValue::create(+ trans('mail.checked_into') ?: '',+ $item->location->name ? $item->location->name : '',+ trans('admin/hardware/form.status').":".$item->assetstatus->name,+ )+ ->onClick(route('hardware.show', $item->id))+ )+ )+ );++ }/*** Get the mail representation of the notification.diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.phpindex 7350a7736b..a2fe275ae2 100644--- a/app/Notifications/CheckoutAssetNotification.php+++ b/app/Notifications/CheckoutAssetNotification.php@@ -11,6 +11,13 @@ 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\Enums\Icon;+use NotificationChannels\GoogleChat\Enums\ImageStyle;+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;@@ -54,13 +61,18 @@ class CheckoutAssetNotification extends Notification*/public function via(){+ $notifyBy = [];+ if (Setting::getSettings()->webhook_selected == 'google'){++ $notifyBy[] = GoogleChatChannel::class;+ }+if (Setting::getSettings()->webhook_selected == 'microsoft'){- return [MicrosoftTeamsChannel::class];+ $notifyBy[] = MicrosoftTeamsChannel::class;}- $notifyBy = [];- if ((Setting::getSettings()) && (Setting::getSettings()->webhook_selected == 'slack')) {+ if ((Setting::getSettings()->webhook_selected == 'slack') || (Setting::getSettings()->webhook_selected == '')) {\Log::debug('use webhook');$notifyBy[] = 'slack';}@@ -143,6 +155,33 @@ class CheckoutAssetNotification extends Notification}+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.Asset_Checkout_Notification').'</strong>' ?: '',+ htmlspecialchars_decode($item->present()->name) ?: '',+ )+ ->section(+ Section::create(+ KeyValue::create(+ trans('mail.assigned_to') ?: '',+ $target->present()->name ?: '',+ $note ?: '',+ )+ ->onClick(route('users.show', $target->id))+ )+ )+ );++ }/*** Get the mail representation of the notification.diff --git a/composer.json b/composer.jsonindex a378f15900..502cb796e2 100644--- a/composer.json+++ b/composer.json@@ -42,6 +42,7 @@"guzzlehttp/guzzle": "^7.0.1","intervention/image": "^2.5","javiereguiluz/easyslugger": "^1.0",+ "laravel-notification-channels/google-chat": "*","laravel-notification-channels/microsoft-teams": "^1.1","laravel/framework": "^8.46","laravel/helpers": "^1.4",diff --git a/composer.lock b/composer.lockindex f4baccc092..8fb4ae80e8 100644--- a/composer.lock+++ b/composer.lock@@ -4,7 +4,7 @@"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies","This file is @generated automatically"],- "content-hash": "89580c52de91168aac8321460bd428e2",+ "content-hash": "bc968c279762208bd4856bb6ebed42c3","packages": [{"name": "alek13/slack",@@ -3188,6 +3188,63 @@},"time": "2015-04-12T19:57:10+00:00"},+ {+ "name": "laravel-notification-channels/google-chat",+ "version": "v1.0.1",+ "source": {+ "type": "git",+ "url": "https://github.com/laravel-notification-channels/google-chat.git",+ "reference": "843078439403a925b484cef99a26b447e30a9c32"+ },+ "dist": {+ "type": "zip",+ "url": "https://api.github.com/repos/laravel-notification-channels/google-chat/zipball/843078439403a925b484cef99a26b447e30a9c32",+ "reference": "843078439403a925b484cef99a26b447e30a9c32",+ "shasum": ""+ },+ "require": {+ "guzzlehttp/guzzle": "^6.3 || ^7.0",+ "illuminate/notifications": "~8.0",+ "illuminate/support": "~8.0",+ "php": ">=7.3"+ },+ "require-dev": {+ "orchestra/testbench": "^6.0",+ "phpunit/phpunit": "^9.0"+ },+ "type": "library",+ "extra": {+ "laravel": {+ "providers": [+ "NotificationChannels\\GoogleChat\\GoogleChatServiceProvider"+ ]+ }+ },+ "autoload": {+ "psr-4": {+ "NotificationChannels\\GoogleChat\\": "src"+ }+ },+ "notification-url": "https://packagist.org/downloads/",+ "license": [+ "MIT"+ ],+ "authors": [+ {+ "name": "Frank Dixon",+ "email": "[email protected]",+ "homepage": "https://thetreehouse.family",+ "role": "Developer"+ }+ ],+ "description": "Google Chat Notification Channel for Laravel (fka. Hangouts Chat)",+ "homepage": "https://github.com/laravel-notification-channels/google-chat",+ "support": {+ "issues": "https://github.com/laravel-notification-channels/google-chat/issues",+ "source": "https://github.com/laravel-notification-channels/google-chat/tree/v1.0.1"+ },+ "time": "2021-07-15T22:40:51+00:00"+ },{"name": "laravel-notification-channels/microsoft-teams","version": "v1.1.4",diff --git a/resources/lang/en-US/admin/hardware/form.php b/resources/lang/en-US/admin/hardware/form.phpindex a7aba0813c..d37d9eac98 100644--- a/resources/lang/en-US/admin/hardware/form.php+++ b/resources/lang/en-US/admin/hardware/form.php@@ -16,7 +16,7 @@ return ['checkedout_to' => 'Checked Out To','checkout_date' => 'Checkout Date','checkin_date' => 'Checkin Date',- 'checkout_to' => 'Checkout to',+ 'checkout_to' => 'Checked out to','cost' => 'Purchase Cost','create' => 'Create Asset','date' => 'Purchase Date',