/laravel-teams-notification

A Laravel package that integrates Microsoft Teams webhook 🔔

Primary LanguagePHPMIT LicenseMIT

A simple Laravel package that integrates Microsoft Teams webhook.

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Installation

You can install the package via composer:

composer require laravel-teams-notification/laravel-teams-notification

You can publish the config file with:

php artisan vendor:publish --tag="laravel-teams-notification-config"

This is the contents of the published config file:

return [
    /*
    |--------------------------------------------------------------------------
    | Webhook URL
    |--------------------------------------------------------------------------
    |
    | The webhook URL where we post a request
    | You can generate test webhook URL in https://typedwebhook.tools/ 
    | or through MS Teams Incoming WebHook
    |
    */
    'webhook_url' => env('WEBHOOK_URL', 'your_webhook_url'),
];

Then, you can add WEBHOOK_URL in your .env file. More information about how to setup webhook in MS teams in this link.

Usage

TeamsNotification::create()
    ->webHookUrl('your_webhook_url')
    ->payload([
        'type' => 'MessageCard',
        'context' => 'https://schema.org/extensions',
        'themeColor' => '0076D7',
        'summary' => 'Hello, World',
        'sections' => [
            [
                'activityTitle' => 'Hello, World!',
            ]
        ]
    ])
    ->dispatch();

Optionally, you can use OrderStatusEvent::class and OrderNotificationListener::class to dispatch order status to MS Teams notifications, of course we can also add more events.

$order_uuid = '123456';
$new_status = 'shipped';
$timestamp = '2023-04-05 01:36:20';

event(new OrderStatusEvent($order_uuid, $new_status, $timestamp));

Screenshot

More samples and screenshot of how the message should look can be found in screenshots folder.

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.