LaravelPackages.net
Acme Inc.
Toggle sidebar
ohffs/laravel-msteams-alerts

Send a message to MS Teams

304
1
1.3.0
About ohffs/laravel-msteams-alerts

ohffs/laravel-msteams-alerts is a Laravel package for send a message to ms teams. It currently has 1 GitHub stars and 304 downloads on Packagist (latest version 1.3.0). Install it with composer require ohffs/laravel-msteams-alerts. Discover more Laravel packages by ohffs or browse all Laravel packages to compare alternatives.

Last updated

Quickly send a message to MS Teams

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.

Star History Chart