PHP code example of oji3t / e2slack

1. Go to this page and download the library: Download oji3t/e2slack 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/ */

    

oji3t / e2slack example snippets


use ExceptionToSlack\Notification;
use FooException;

try {
    throw new FooException;
} catch (FooException $e) {
    $config = ['endpoint' => YOUR_WEBHOOK_ENDPOINT];
    $notification = new Notification($e, $config);
    $notification->send();
}

use FooException;

try {
    throw new FooException;
} catch (FooException $e) {
    $config = ['endpoint' => YOUR_WEBHOOK_ENDPOINT];
    e2slack($e, $config);
}

use ExceptionToSlack\Notification;
use FooException;

try {
    throw new FooException;
} catch (FooException $e) {
    $config = ['endpoint' => YOUR_WEBHOOK_ENDPOINT];
    $notification = new Notification($e, $config);
    $notification->setUsername('Debug Bot');
    $notification->setChannel('@user.name');
    $notification->setIcon(':love_letter:');
    $notification->send();
}

// config/services.php
return [
    // ~~~

    'e2slack' => [
        'endpoint' => env('SLACK_ENDPOINT'),
        'channel' => env('SLACK_CHANNEL'),
        'username' => env('SLACK_USERNAME'),
        'icon' => env('SLACK_ICON'),
    ],
];

// app/Exceptions/Handler.php
namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Response;
use App\Exceptions\FooException;
use ExceptionToSlack\Notification;

class Handler extends ExceptionHandler
{
    // ~~~

    public function render($request, Exception $e)
    {
        if ($e instanceof FooException) {
            $notification = new Notification($e, config('services.e2slack'));
            $notification->send();
        }

        return parent::render($request, $e);
    }
}