diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php index 228c4c2e95..d7999e9387 100644 --- a/app/Notifications/CheckoutConsumableNotification.php +++ b/app/Notifications/CheckoutConsumableNotification.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; @@ -44,6 +49,10 @@ class CheckoutConsumableNotification extends Notification public function via() { $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'google'){ + + $notifyBy[] = GoogleChatChannel::class; + } if (Setting::getSettings()->webhook_selected == 'microsoft'){ @@ -128,6 +137,33 @@ class CheckoutConsumableNotification extends Notification ->fact(trans('admin/consumables/general.remaining'), $item->numRemaining()) ->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.Consumable_checkout_notification').'' ?: '', + htmlspecialchars_decode($item->present()->name) ?: '', + ) + ->section( + Section::create( + KeyValue::create( + trans('mail.assigned_to') ?: '', + $target->present()->fullName() ?: '', + trans('admin/consumables/general.remaining').': '.$item->numRemaining(), + ) + ->onClick(route('users.show', $target->id)) + ) + ) + ); + + } /** * Get the mail representation of the notification.