paulgsepulveda/monolog-teams-workflow

Monolog Handler for sending messages to Microsoft Teams channels using the Workflow webhook

v1.0.0 2024-07-16 18:37 UTC

This package is not auto-updated.

Last update: 2025-07-16 22:04:45 UTC


README

Monolog Handler for sending messages to Microsoft Teams channels using Workflow / Power Automate. I put this together based on monolog-microsoft-teams after Microsoft retired Office 365 connectors.

This is a fork of the original paulgsepulveda/monolog-teams-workflow repository making it available for PHP version 8.1

Install

$ composer require Metamorfer/monolog-teams-workflow

Configuring Workflow

  • Install the app Power Automate on the Teams channel that is intended to receive the log messages
  • Create a new Workflow using the template Post to a channel when a webhook request is received.
  • The JSON formatting assumes that the Select an output from previous steps field will remain set to attachments
  • The JSON formatting assumes that the Adaptive Card field under Post your own adaptive card will remain set to content
  • After saving the workflow, the When a Teams webhook request is received card will provide the HTTP POST URL value to use for the incoming webhook.

Usage

$logger = new \Monolog\Logger('app');
$logger->pushHandler(new \Metamorfer\MonologTeamsWorkflow\TeamsWorkflowLogHandler('INCOMING_WEBHOOK_URL', \Monolog\Level::Error));

$logger->error('Error message');

Usage with Laravel/Lumen framework (5.6+)

Create a custom channel

config/logging.php

'teams' => [
    'driver' => 'custom',
    'via' => \Metamorfer\MonologTeamsWorkflow\TeamsLogChannel::class,
    'level' => 'error',
    'url' => 'INCOMING_WEBHOOK_URL',
    'source_name' => env('APP_NAME'),
    'source_url' => env('APP_URL'),
],

source_name and source_url are included since the receiving channel may be receiving notifications from more than one site.

Send an error message to the teams channel:

Log::channel('teams')->error('Error message');

You can also add teams to the default stack channel so all errors are automatically send to the teams channel.

'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'teams'],
    ],
],

Unit testing ยท PhpUnit

The tests require a valid incoming Workflow webhook url. Follow the steps above in Configuring Workflow to generate this. To provide this URL to PhpUnit, copy phpunit.xml.dist to phpunit.xmland set the URL in the <php> section. Make sure to not commit your local phpunit.xml into the repo!

<php>
    <env name="TEAMS_INCOMING_WEBHOOK_URL" value="..." />
</php>

Run the tests on the command line:

$ composer test

License

monolog-teams-workflow is available under the MIT license. See the LICENSE file for more info.