fix checkoutable listener for microsoft teams
This commit is contained in:
parent
18760e3fa1
commit
18da80e6de
2 changed files with 39 additions and 20 deletions
|
@ -23,6 +23,7 @@ use GuzzleHttp\Exception\ClientException;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Osama\LaravelTeamsNotification\TeamsNotification;
|
||||||
|
|
||||||
class CheckoutableListener
|
class CheckoutableListener
|
||||||
{
|
{
|
||||||
|
@ -48,16 +49,16 @@ class CheckoutableListener
|
||||||
|
|
||||||
// Send email notifications
|
// Send email notifications
|
||||||
try {
|
try {
|
||||||
foreach ($notifiables as $notifiable) {
|
// foreach ($notifiables as $notifiable) {
|
||||||
if ($notifiable instanceof User && $notifiable->email != '') {
|
// if ($notifiable instanceof User && $notifiable->email != '') {
|
||||||
if (! $event->checkedOutTo->locale){
|
// if (! $event->checkedOutTo->locale){
|
||||||
Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance));
|
// Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance));
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance));
|
// Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Send Webhook notification
|
// Send Webhook notification
|
||||||
if ($this->shouldSendWebhookNotification()) {
|
if ($this->shouldSendWebhookNotification()) {
|
||||||
|
@ -65,7 +66,15 @@ class CheckoutableListener
|
||||||
if (Setting::getSettings()->webhook_selected === 'slack' || Setting::getSettings()->webhook_selected === 'general') {
|
if (Setting::getSettings()->webhook_selected === 'slack' || Setting::getSettings()->webhook_selected === 'general') {
|
||||||
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
||||||
->notify($this->getCheckoutNotification($event, $acceptance));
|
->notify($this->getCheckoutNotification($event, $acceptance));
|
||||||
} else {
|
}
|
||||||
|
// Handling Microsoft Teams notification
|
||||||
|
else if (Setting::getSettings()->webhook_selected === 'microsoft') {
|
||||||
|
|
||||||
|
$message = $this->getCheckoutNotification($event)->toMicrosoftTeams();
|
||||||
|
$notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint);
|
||||||
|
$notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams
|
||||||
|
}
|
||||||
|
else {
|
||||||
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
|
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
|
||||||
->notify($this->getCheckoutNotification($event, $acceptance));
|
->notify($this->getCheckoutNotification($event, $acceptance));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ use NotificationChannels\GoogleChat\Widgets\KeyValue;
|
||||||
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
|
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
|
||||||
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;
|
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Osama\LaravelTeamsNotification\Logging\TeamsLoggingChannel;
|
||||||
use Osama\LaravelTeamsNotification\TeamsNotification;
|
use Osama\LaravelTeamsNotification\TeamsNotification;
|
||||||
|
|
||||||
class CheckoutAssetNotification extends Notification
|
class CheckoutAssetNotification extends Notification
|
||||||
|
@ -147,15 +148,24 @@ class CheckoutAssetNotification extends Notification
|
||||||
$item = $this->item;
|
$item = $this->item;
|
||||||
$note = $this->note;
|
$note = $this->note;
|
||||||
|
|
||||||
return MicrosoftTeamsMessage::create()
|
$notification = new TeamsNotification($this->settings->webhook_channel);
|
||||||
->to($this->settings->webhook_endpoint)
|
$message = trans('mail.Asset_Checkout_Notification');
|
||||||
->type('success')
|
$details = [
|
||||||
->title(trans('mail.Asset_Checkout_Notification'))
|
trans('mail.assigned_to') => $target->present()->name,
|
||||||
->addStartGroupToSection('activityText')
|
htmlspecialchars_decode($item->present()->name) => '',
|
||||||
->fact(trans('mail.assigned_to'), $target->present()->name)
|
trans('mail.Asset_Checkout_Notification'). ' by' => $admin->present()->fullName(),
|
||||||
->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText')
|
trans('mail.notes') => $note ?: '',
|
||||||
->fact(trans('mail.Asset_Checkout_Notification') . " by ", $admin->present()->fullName())
|
];
|
||||||
->fact(trans('mail.notes'), $note ?: '');
|
return array($message, $details);
|
||||||
|
// return MicrosoftTeamsMessage::create()
|
||||||
|
// ->to($this->settings->webhook_endpoint)
|
||||||
|
// ->type('success')
|
||||||
|
// ->title()
|
||||||
|
// ->addStartGroupToSection('activityText')
|
||||||
|
// ->fact(trans('mail.assigned_to'), $target->present()->name)
|
||||||
|
// ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText')
|
||||||
|
// ->fact(trans('mail.Asset_Checkout_Notification') . " by ", $admin->present()->fullName())
|
||||||
|
// ->fact(trans('mail.notes'), $note ?: '');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue