Skip to content

Commit

Permalink
adds google notif to consumable check out
Browse files Browse the repository at this point in the history
  • Loading branch information
Godmartinz committed Jan 30, 2024
1 parent 2406d2c commit 0eabb14
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/Notifications/CheckoutConsumableNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
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;

Expand Down Expand Up @@ -44,6 +49,10 @@ public function __construct(Consumable $consumable, $checkedOutTo, User $checked
public function via()
{
$notifyBy = [];
if (Setting::getSettings()->webhook_selected == 'google'){

$notifyBy[] = GoogleChatChannel::class;
}

if (Setting::getSettings()->webhook_selected == 'microsoft'){

Expand Down Expand Up @@ -128,6 +137,33 @@ public function toMicrosoftTeams()
->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(
'<strong>'.trans('mail.Consumable_checkout_notification').'</strong>' ?: '',
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.
Expand Down

0 comments on commit 0eabb14

Please sign in to comment.