ohffs / laravel-msteams-alerts
Send a message to MS Teams
Requires
- php: ^8.0
- illuminate/contracts: ^8.73|^9.0|^10.0|^11.0|^12.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^5.10|^6.0
- nunomaduro/larastan: ^1.0|2.0
- orchestra/testbench: ^6.22
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
README
This package can quickly send alerts to Microsoft Teams. You can use this to notify yourself of any noteworthy events happening in your Laravel app. This is a fork of Spatie's laravel-slack-alerts so all thanks to them for doing the main bulk of the work. I've pretty much just changed 'Slack' to 'MSTeams'.
use Ohffs\MSTeamsAlerts\Facades\MSTeamsAlert; MSTeamsAlert::message("You have a new subscriber to the {$newsletter->name} newsletter!");
Under the hood, a job is used to communicate with MS Teams. This prevents your app from failing in case Teams is down.
Want to send alerts to Discord or Slack instead? Check out laravel-discord-alerts and laravel-slack-alerts.
Installation
You can install the package via composer:
composer require ohffs/laravel-msteams-alerts
You can set a MSTEAMS_ALERT_WEBHOOK
env variable containing a valid Teams webhook URL. You can learn how to get a webhook URL in the Teams docs.
Alternatively, you can publish the config file with:
php artisan vendor:publish --tag="msteams-alerts-config"
This is the contents of the published config file:
return [ /* * The webhook URLs that we'll use to send a message to Teams. */ 'webhook_urls' => [ 'default' => env('MSTEAMS_ALERT_WEBHOOK'), ], /* * This job will send the message to Teams. You can extend this * job to set timeouts, retries, etc... */ 'job' => Ohffs\MSTeamsAlerts\Jobs\SendToMSTeamsChannelJob::class, ];
Usage
To send a message to Teams, simply call MSTeamsAlert::message()
and pass it any message you want.
MSTeamsAlert::message("You have a new subscriber to the {$newsletter->name} newsletter!");
Using multiple webhooks
You can also use an alternative webhook, by specify extra ones in the config file.
// in config/msteams-alerts.php 'webhook_urls' => [ 'default' => 'https://hooks.office.com/services/XXXXXX', 'marketing' => 'https://hooks.office.com/services/YYYYYY', ],
The webhook to be used can be chosen using the to
function.
use Ohffs\MSTeamsAlerts\Facades\MSTeamsAlert; MSTeamsAlert::to('marketing')->message("You have a new subscriber to the {$newsletter->name} newsletter!");
Using a custom webhooks
The to
function also supports custom webhook urls.
use Ohffs\MSTeamsAlerts\Facades\MSTeamsAlert; MSTeamsAlert::to('https://custom-url.com')->message("You have a new subscriber to the {$newsletter->name} newsletter!");
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.