fix: slack channel

This commit is contained in:
Stefan Stidl 2023-06-02 11:59:47 +02:00 committed by Stefan Stidl
parent ff480a7247
commit ad8c36a51a
10 changed files with 22 additions and 0 deletions

View file

@ -23,6 +23,7 @@ class AuditNotification extends Notification
public function __construct($params) public function __construct($params)
{ {
// //
$this->settings = Setting::getSettings();
$this->params = $params; $this->params = $params;
} }
@ -43,9 +44,12 @@ class AuditNotification extends Notification
public function toSlack() public function toSlack()
{ {
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
return (new SlackMessage) return (new SlackMessage)
->success() ->success()
->content(class_basename(get_class($this->params['item'])).' Audited') ->content(class_basename(get_class($this->params['item'])).' Audited')
->from(($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot')
->to($channel)
->attachment(function ($attachment) { ->attachment(function ($attachment) {
$item = $this->params['item']; $item = $this->params['item'];
$admin_user = $this->params['admin']; $admin_user = $this->params['admin'];

View file

@ -92,6 +92,7 @@ class CheckinAccessoryNotification extends Notification
$item = $this->item; $item = $this->item;
$note = $this->note; $note = $this->note;
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
$fields = [ $fields = [
'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
@ -101,6 +102,7 @@ class CheckinAccessoryNotification extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(':arrow_down: :keyboard: '.trans('mail.Accessory_Checkin_Notification')) ->content(':arrow_down: :keyboard: '.trans('mail.Accessory_Checkin_Notification'))
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $admin, $fields) { ->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)

View file

@ -65,6 +65,7 @@ class CheckinAssetNotification extends Notification
$item = $this->item; $item = $this->item;
$note = $this->note; $note = $this->note;
$botname = ($this->settings->webhook_botname != '') ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname != '') ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
$fields = [ $fields = [
trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>', trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>',
@ -75,6 +76,7 @@ class CheckinAssetNotification extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(':arrow_down: :computer: '.trans('mail.Asset_Checkin_Notification')) ->content(':arrow_down: :computer: '.trans('mail.Asset_Checkin_Notification'))
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $admin, $fields) { ->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)

View file

@ -63,6 +63,7 @@ class CheckinLicenseSeatNotification extends Notification
$item = $this->item; $item = $this->item;
$note = $this->note; $note = $this->note;
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
if ($admin) { if ($admin) {
$fields = [ $fields = [
@ -79,6 +80,7 @@ class CheckinLicenseSeatNotification extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(':arrow_down: :floppy_disk: '.trans('mail.License_Checkin_Notification')) ->content(':arrow_down: :floppy_disk: '.trans('mail.License_Checkin_Notification'))
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $admin, $fields) { ->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)

View file

@ -79,6 +79,7 @@ class CheckoutAccessoryNotification extends Notification
$item = $this->item; $item = $this->item;
$note = $this->note; $note = $this->note;
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
$fields = [ $fields = [
'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
@ -88,6 +89,7 @@ class CheckoutAccessoryNotification extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(':arrow_up: :keyboard: Accessory Checked Out') ->content(':arrow_up: :keyboard: Accessory Checked Out')
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $admin, $fields) { ->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)

View file

@ -96,6 +96,7 @@ class CheckoutAssetNotification extends Notification
$item = $this->item; $item = $this->item;
$note = $this->note; $note = $this->note;
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
$fields = [ $fields = [
'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
@ -109,6 +110,7 @@ class CheckoutAssetNotification extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(':arrow_up: :computer: '.trans('mail.Asset_Checkout_Notification')) ->content(':arrow_up: :computer: '.trans('mail.Asset_Checkout_Notification'))
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $admin, $fields) { ->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)

View file

@ -85,6 +85,7 @@ class CheckoutConsumableNotification extends Notification
$item = $this->item; $item = $this->item;
$note = $this->note; $note = $this->note;
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
$fields = [ $fields = [
'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
@ -94,6 +95,7 @@ class CheckoutConsumableNotification extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(':arrow_up: :paperclip: Consumable Checked Out') ->content(':arrow_up: :paperclip: Consumable Checked Out')
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $admin, $fields) { ->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)

View file

@ -85,6 +85,7 @@ class CheckoutLicenseSeatNotification extends Notification
$item = $this->item; $item = $this->item;
$note = $this->note; $note = $this->note;
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
$fields = [ $fields = [
'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
@ -94,6 +95,7 @@ class CheckoutLicenseSeatNotification extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(':arrow_up: :floppy_disk: License Checked Out') ->content(':arrow_up: :floppy_disk: License Checked Out')
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $admin, $fields) { ->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)

View file

@ -74,6 +74,7 @@ class RequestAssetCancelation extends Notification
$note = $this->note; $note = $this->note;
$qty = $this->item_quantity; $qty = $this->item_quantity;
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
$fields = [ $fields = [
'QTY' => $qty, 'QTY' => $qty,
@ -87,6 +88,7 @@ class RequestAssetCancelation extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(trans('mail.a_user_canceled')) ->content(trans('mail.a_user_canceled'))
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $fields) { ->attachment(function ($attachment) use ($item, $note, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)

View file

@ -74,6 +74,7 @@ class RequestAssetNotification extends Notification
$item = $this->item; $item = $this->item;
$note = $this->note; $note = $this->note;
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
$fields = [ $fields = [
'QTY' => $qty, 'QTY' => $qty,
@ -83,6 +84,7 @@ class RequestAssetNotification extends Notification
return (new SlackMessage) return (new SlackMessage)
->content(trans('mail.Item_Requested')) ->content(trans('mail.Item_Requested'))
->from($botname) ->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $fields) { ->attachment(function ($attachment) use ($item, $note, $fields) {
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl()) $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
->fields($fields) ->fields($fields)