added google chat to audit notifications"
This commit is contained in:
@@ -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))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user