paulgsepulveda/monolog-teams-workflow
最新稳定版本:v1.0.0
Composer 安装命令:
composer require paulgsepulveda/monolog-teams-workflow
包简介
Monolog Handler for sending messages to Microsoft Teams channels using the Workflow webhook
README 文档
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 Automateon 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 URLvalue 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.
统计信息
- 总下载量: 1.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-16