Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Google Chat notifications #14191

Merged
merged 16 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adds google notifs to accessories check in and out
  • Loading branch information
Godmartinz committed Jan 30, 2024
commit e074ca0bf958c52063127205ecd77d072bb00566
36 changes: 36 additions & 0 deletions app/Notifications/CheckinAccessoryNotification.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 @@ -38,6 +43,10 @@ public function __construct(Accessory $accessory, $checkedOutTo, User $checkedIn
public function via()
{
$notifyBy = [];
if (Setting::getSettings()->webhook_selected == 'google'){

$notifyBy[] = GoogleChatChannel::class;
}

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

Expand Down Expand Up @@ -132,6 +141,33 @@ public function toMicrosoftTeams()
->fact(trans('admin/consumables/general.remaining'), $item->numRemaining())
->fact(trans('mail.notes'), $note ?: '');
}
public function toGoogleChat()
{
$item = $this->item;
$note = $this->note;

return GoogleChatMessage::create()
->to($this->settings->webhook_endpoint)
->card(
Card::create()
->header(
'<strong>'.trans('mail.Accessory_Checkin_Notification').'</strong>' ?: '',
htmlspecialchars_decode($item->present()->name) ?: '',
)
->section(
Section::create(
KeyValue::create(
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))
)
)
);

}

/**
* Get the mail representation of the notification.
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/CheckinAssetNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function toGoogleChat()
KeyValue::create(
trans('mail.checked_into') ?: '',
$item->location->name ? $item->location->name : '',
trans('admin/hardware/form.status').":".$item->assetstatus->name,
trans('admin/hardware/form.status').": ".$item->assetstatus->name,
)
->onClick(route('hardware.show', $item->id))
)
Expand Down
37 changes: 37 additions & 0 deletions app/Notifications/CheckoutAccessoryNotification.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 @@ -37,6 +42,10 @@ public function __construct(Accessory $accessory, $checkedOutTo, User $checkedOu
public function via()
{
$notifyBy = [];
if (Setting::getSettings()->webhook_selected == 'google'){

$notifyBy[] = GoogleChatChannel::class;
}

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

Expand Down Expand Up @@ -123,6 +132,34 @@ public function toMicrosoftTeams()
->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.Accessory_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->numRemaining(),
)
->onClick(route('users.show', $target->id))
)
)
);

}


/**
* Get the mail representation of the notification.
Expand Down