Skip to content

About

Slack Channel WebHook Integration For Filament Alerts Sender

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Screenshot

Filament Slack Driver

Dependabot Updates PHP Code Styling Tests Latest Stable Version License Downloads

Slack Channel Integration for Filament Alerts Sender

Send your alerts to Slack through an incoming webhook, or through a bot token and chat.postMessage. The title, body, image and action URL are rendered as a Block Kit message.

Screenshots

Light Dark
Settings Settings
Settings Hub Settings Hub
Driver Driver

Requirements

Package version Filament Laravel PHP
5.x 5.x 12.x, 13.x 8.2+

Installation

composer require tomatophp/filament-slack-driver

after install your package please run this command

php artisan filament-slack-driver:install

finally register the plugin on /app/Providers/Filament/AdminPanelProvider.php

->plugin(\TomatoPHP\FilamentSlackDriver\FilamentSlackDriverPlugin::make())

Configuration

open the Slack settings page from the settings hub and fill in either an incoming webhook, or a bot token with a default channel. The webhook and the bot token are write-only, they are never sent back to the browser, and leaving an input empty keeps the value that is already stored.

you can also set the values from your .env file, a saved setting always wins over the env value:

SLACK_WEBHOOK=https://hooks.slack.com/services/T000/B000/xxxx
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_CHANNEL=#general
SLACK_ACTIVE=true

when nothing is configured, or when the driver is switched off, nothing is sent and nothing is logged.

Usage

to set up any model to get notifications you

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use TomatoPHP\FilamentSlackDriver\Traits\InteractsWithSlack;

class User extends Authenticatable
{
    use HasFactory;
    use Notifiable;
    use InteractsWithSlack;
    ...

Queue

the notification is run on queue, so you must run the queue worker to send the notifications

php artisan queue:work

Use Filament Native Notification

you can use the filament native notification and we add some macro for you

use Filament\Notifications\Notification;

Notification::make('send')
    ->title('Test Notifications')
    ->body('This is a test notification')
    ->icon('heroicon-o-bell')
    ->color('success')
    ->actions([
        \Filament\Notifications\Actions\Action::make('view')
            ->label('View')
            ->url('https://google.com')
            ->markAsRead()
    ])
    ->sendUse(auth()->user(), \TomatoPHP\FilamentSlackDriver\Services\SlackDriver::class, ['image' => 'https://via.placeholder.com/150']);

Notification Service

to create a new template you can use template CRUD and make sure that the template key is unique because you will use it on every single notification.

Send Notification

to send a notification you must use our helper SendNotification::class like

use TomatoPHP\FilamentAlerts\Facades\FilamentAlerts;

FilamentAlerts::notify(User::first())
    ->template($template->id)
    ->title([
        "find-text" => "change with this"
    ])
    ->body([
        "find-text" => "change with this"
    ])
    ->drivers(\TomatoPHP\FilamentSlackDriver\Services\SlackDriver::class)
    ->data(['channel' => '#releases'])
    ->send();

where $template is selected of the template by key or id, and title, body use to select and replace string on the template with custom data. the channel data key overrides the default channel, it only applies when you send with a bot token.

Notification Channels

it can be working with direct user methods like

$user->notifySlack(string $title, ?string $message = null, ?string $url = null, ?string $image = null, ?string $channel = null);

Publish Assets

you can publish config file by use this command

php artisan vendor:publish --tag="filament-slack-driver-config"

you can publish languages file by use this command

php artisan vendor:publish --tag="filament-slack-driver-lang"

Testing

if you like to run PEST testing just use this command

composer test

Code Style

if you like to fix the code style just use this command

composer format

PHPStan

if you like to check the code by PHPStan just use this command

composer analyse

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security

Please see SECURITY for more information about security.

Credits

License

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

Other Filament Packages

Checkout our Awesome TomatoPHP

About

Slack Channel WebHook Integration For Filament Alerts Sender

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages