Skip to content

A free open source IT asset/license management system

added google chat to audit notifications"

Godfrey M24d7ae4a2f99
diff --git a/app/Notifications/AuditNotification.php b/app/Notifications/AuditNotification.php
index fecb66f350..af94cefddc 100644
--- a/app/Notifications/AuditNotification.php
+++ b/app/Notifications/AuditNotification.php
@@ -10,6 +10,11 @@ use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
+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;
use Symfony\Component\Mime\Email;
@@ -55,6 +60,10 @@ class AuditNotification extends Notification
$notifyBy[] = MicrosoftTeamsChannel::class;
}
+ if (Setting::getSettings()->webhook_selected == 'google' && Setting::getSettings()->webhook_endpoint) {
+ Log::debug('using google webhook');
+ $notifyBy[] = GoogleChatChannel::class;
+ }
return $notifyBy;
}
@@ -110,4 +119,35 @@ class AuditNotification extends Notification
];
return [$message, $details];
}
+ public function toGoogleChat()
+ {
+ $item = $this->params['item'] ?? null;
+ $admin_user = $this->params['admin'] ?? null;
+ $note = $this->params['note'] ?? '';
+ $setting = $this->settings ?? Setting::getSettings();
+
+ $title = '<strong>' . class_basename($item) . ' ' . trans('general.audited') . '</strong>';
+ $subtitle = htmlspecialchars_decode($item->display_name ?? '');
+ \Log::debug('Google Chat audit payload', [
+ 'title' => $title,
+ 'subtitle' => $subtitle,
+ 'admin' => $admin_user->display_name,
+ 'note' => $note,
+ ]);
+ return GoogleChatMessage::create()
+ ->to($setting->webhook_endpoint)
+ ->card(
+ Card::create()
+ ->header($title, $subtitle)
+ ->section(
+ Section::create(
+ KeyValue::create(
+ trans('general.audited_by'),
+ $admin_user?->display_name ?? '',
+ $note ?? ''
+ )->onClick(route('hardware.show', $item->id))
+ )
+ )
+ );
+ }
}