parhamafkar/laravel-mattermost

Laravel package to log messages to Mattermost using both Bot API and Webhooks

v1.0.1 2025-06-04 20:12 UTC

This package is auto-updated.

Last update: 2025-07-04 21:45:15 UTC


README

This Laravel package is designed to support both bot and webhook integrations with Mattermost.
It supports sending logs to a custom channel for each log action, allowing more control and visibility.

📦 Installation

Install the package using Composer:

composer require parhamafkar/laravel-mattermost

⚙️ Configuration

1. Publish the config file

php artisan vendor:publish --tag=config

2. Add the custom log driver to config/logging.php

'mattermost' => [
    'driver' => 'custom',
    'via' => ParhamAfkar\MattermostLogger\Mattermost::class,
    'level' => 'debug',
    'webhook_url' => env('MATTERMOST_WEBHOOK_URL'),
    'channel' => env('MATTERMOST_CHANNEL'),
    'username' => env('MATTERMOST_USERNAME', 'Mattermost'),
],

3. Update the stack channel in config/logging.php

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

4. Add the following variables to your .env file

MATTERMOST_BASE_URL="https://xyz.mattermost.xyz"
MATTERMOST_BOT_TOKEN="<bot-token>"
MATTERMOST_BOT_USERNAME="Parham-Bot"
MATTERMOST_WEBHOOK_URL=https://xyz.mattermost.xyz/hooks/<incoming-hooks-token>
MATTERMOST_TYPE=bot # bot or webhook
MATTERMOST_CHANNEL=errors
MATTERMOST_CHANNEL_PREFIX="develop-" # output: develop-errors

✅ Usage

All logs will be sent to MATTERMOST_CHANNEL=errors by default once the stack is configured.
However, you can also send logs manually anywhere in your application. For example, in a controller:

<?php

namespace App\Http\Controllers;

use ParhamAfkar\MattermostLogger\Facades\Mattermost;

class MyController extends Controller
{
    public function index()
    {
        Mattermost::channel('errors')->error('Error message', [
            'user_id' => 1,
            'request' => "test",
        ]);

        Mattermost::channel('debug')->info('Info message', [
            'user_id' => 1,
            'request' => "test",
        ]);

        Mattermost::channel('exceptions')->exception($e);

        // warning
        // debug
    }
}