PHP code example of talvbansal / laravel-ms-teams-notification-channel

1. Go to this page and download the library: Download talvbansal/laravel-ms-teams-notification-channel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

talvbansal / laravel-ms-teams-notification-channel example snippets


// config/services.php
...
'ms-teams' => [
    'webhook_url' => env('MS_TEAMS_WEBHOOK_URL', 'WEBHOOK URL HERE')
],
...

// config/services.php
...
'ms-teams' => [
    'developers_webhook_url' => env('MS_TEAMS_DEVELOPERS_WEBHOOK_URL'),
    'helpdesk_webhook_url' => env('MS_TEAMS_HELPDESK_WEBHOOK_URL'),
],
...


use NotificationChannels\MsTeams\MsTeamsChannel;
use NotificationChannels\MsTeams\MsTeamsMessage;
use Illuminate\Notifications\Notification;

class InvoicePaid extends Notification
{
    public function via($notifiable)
    {
        return [MsTeamsChannel::class];
    }

    public function toMsTeams($notifiable)
    {
        $url = url('/invoice/' . $this->invoice->id);

        return MsTeamsMessage::create()
            // Optional recipient user id.
            ->to(config('services.ms-teams.webhook_url'))
            // Markdown supported.
            ->content("Hello there!\nYour invoice has been *PAID*")
            // (Optional) Inline Buttons
            ->button('View Invoice', $url)
            ->button('Download Invoice', $url)
            // (Optional) Supporting images
            ->image('https://source.unsplash.com/random/800x800?animals,nature&q='.now())
            ->image('https://source.unsplash.com/random/900x600?building,car&q='.now());
    }
}


...
/**
 * Route notifications for the MS Teams channel.
 *
 * @return int
 */
public function routeNotificationForMsTeams()
{
    return config('services.ms-teams.webhook_url');
}
...