formats check in message for MS Teams

This commit is contained in:
Godfrey M 2024-01-17 17:31:23 -08:00
parent ce02e43ab2
commit cdcd868162
3 changed files with 78 additions and 28 deletions

View file

@ -10,6 +10,8 @@ use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;
class CheckinAssetNotification extends Notification
{
@ -42,7 +44,10 @@ class CheckinAssetNotification extends Notification
* @return array
*/
public function via()
{
{ if (Setting::getSettings()->webhook_selected == 'microsoft'){
return [MicrosoftTeamsChannel::class];
}
$notifyBy = [];
if (Setting::getSettings()->webhook_endpoint != '') {
\Log::debug('use webhook');
@ -84,40 +89,27 @@ class CheckinAssetNotification extends Notification
->content($note);
});
}
public function toMsTeams()
public function toMicrosoftTeams()
{
$admin = $this->admin;
$item = $this->item;
$note = $this->note;
$fields = [
$button = [
trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>',
trans('general.status') => $item->assetstatus->name,
trans('general.location') => ($item->location) ? $item->location->name : '',
];
$payload = json_encode(
[
"type" => "message",
"attachments" => [
[
"contentType" => "application/vnd.microsoft.card.adaptive",
"contentUrl" => null,
"content" => [
"schema" => "http://adaptivecards.io/schemas/adaptive-card.json",
"type" => "AdaptiveCard",
"version" => "1.2",
"body" => [
[
"type" => "TextBlock",
"text" => "For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)"
]
]
]
]
]
]
);
return MicrosoftTeamsMessage::create()
->to($this->settings->webhook_endpoint)
->type('success')
->title("Asset Checked in")
->fact($item->present()->name, '')
->fact('Checked into ', $item->location->name)
->fact(trans('mail.Asset_Checkin_Notification')." by ", $admin->present()->fullName())
->fact('Asset Status', $item->assetstatus->name);
}

View file

@ -42,6 +42,7 @@
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.5",
"javiereguiluz/easyslugger": "^1.0",
"laravel-notification-channels/microsoft-teams": "^1.1",
"laravel/framework": "^8.46",
"laravel/helpers": "^1.4",
"laravel/passport": "^10.1",

61
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f4f3b6b02d044ed3e54cdd509b01c3dc",
"content-hash": "89580c52de91168aac8321460bd428e2",
"packages": [
{
"name": "alek13/slack",
@ -3180,6 +3180,63 @@
},
"time": "2015-04-12T19:57:10+00:00"
},
{
"name": "laravel-notification-channels/microsoft-teams",
"version": "v1.1.4",
"source": {
"type": "git",
"url": "https://github.com/laravel-notification-channels/microsoft-teams.git",
"reference": "e2df0129ba430666979eb2ad7033455fd0f6b577"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel-notification-channels/microsoft-teams/zipball/e2df0129ba430666979eb2ad7033455fd0f6b577",
"reference": "e2df0129ba430666979eb2ad7033455fd0f6b577",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"illuminate/notifications": "~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0 || ^10.0",
"illuminate/support": "~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0 || ^10.0",
"php": ">=7.2"
},
"require-dev": {
"mockery/mockery": "^1.2.3",
"phpunit/phpunit": "^8.0|^9.5"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"NotificationChannels\\MicrosoftTeams\\MicrosoftTeamsServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"NotificationChannels\\MicrosoftTeams\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Tobias Madner",
"email": "tobias.madner@gmx.at",
"homepage": "https://www.pinpoll.com",
"role": "Developer"
}
],
"description": "A Laravel Notification Channel for Microsoft Teams",
"homepage": "https://github.com/laravel-notification-channels/microsoft-teams",
"support": {
"issues": "https://github.com/laravel-notification-channels/microsoft-teams/issues",
"source": "https://github.com/laravel-notification-channels/microsoft-teams/tree/v1.1.4"
},
"time": "2023-01-25T16:56:40+00:00"
},
{
"name": "laravel/framework",
"version": "v8.83.22",
@ -16961,5 +17018,5 @@
"ext-pdo": "*"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
"plugin-api-version": "2.3.0"
}