Skip to content

Commit

Permalink
adds google notifs to license seats check in and out
Browse files Browse the repository at this point in the history
  • Loading branch information
Godmartinz committed Jan 30, 2024
1 parent e074ca0 commit 2406d2c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
1 change: 0 additions & 1 deletion app/Notifications/CheckinAccessoryNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public function toGoogleChat()
trans('mail.checked_into').': '.$item->location->name ? $item->location->name : '',
trans('admin/consumables/general.remaining').': '.$item->numRemaining(),
trans('admin/hardware/form.notes').": ".$note ?: '',

)
->onClick(route('accessories.show', $item->id))
)
Expand Down
37 changes: 37 additions & 0 deletions app/Notifications/CheckinLicenseSeatNotification.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 @@ -43,6 +48,10 @@ public function via()
{
$notifyBy = [];

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

$notifyBy[] = GoogleChatChannel::class;
}
if (Setting::getSettings()->webhook_selected == 'microsoft'){

$notifyBy[] = MicrosoftTeamsChannel::class;
Expand Down Expand Up @@ -113,6 +122,34 @@ public function toMicrosoftTeams()
->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count())
->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.License_Checkin_Notification').'</strong>' ?: '',
htmlspecialchars_decode($item->present()->name) ?: '',
)
->section(
Section::create(
KeyValue::create(
trans('mail.checkedin_from') ?: '',
$target->present()->fullName() ?: '',
trans('admin/consumables/general.remaining').': '.$item->availCount()->count(),
)
->onClick(route('licenses.show', $item->id))
)
)
);

}


/**
* Get the mail representation of the notification.
Expand Down
37 changes: 36 additions & 1 deletion app/Notifications/CheckoutLicenseSeatNotification.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 @@ -43,9 +48,12 @@ public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $check
*/
public function via()
{

$notifyBy = [];

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

$notifyBy[] = GoogleChatChannel::class;
}
if (Setting::getSettings()->webhook_selected == 'microsoft'){

$notifyBy[] = MicrosoftTeamsChannel::class;
Expand Down Expand Up @@ -129,6 +137,33 @@ public function toMicrosoftTeams()
->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count())
->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.License_Checkout_Notification').'</strong>' ?: '',
htmlspecialchars_decode($item->present()->name) ?: '',
)
->section(
Section::create(
KeyValue::create(
trans('mail.assigned_to') ?: '',
$target->present()->name ?: '',
trans('admin/consumables/general.remaining').': '.$item->availCount()->count(),
)
->onClick(route('users.show', $target->id))
)
)
);

}

/**
* Get the mail representation of the notification.
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en-US/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'checkin_date' => 'Checkin Date:',
'checkout_date' => 'Checkout Date:',
'checkedout_from' => 'Checked out from',
'checkedin_from' => 'Checked in from',
'checked_into' => 'Checked into',
'click_on_the_link_accessory' => 'Please click on the link at the bottom to confirm that you have received the accessory.',
'click_on_the_link_asset' => 'Please click on the link at the bottom to confirm that you have received the asset.',
Expand Down

0 comments on commit 2406d2c

Please sign in to comment.