PHP code example of denoby / laravel-telegram-logger

1. Go to this page and download the library: Download denoby/laravel-telegram-logger 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/ */

    

denoby / laravel-telegram-logger example snippets


'channels' => [
    // ... other channels

    'telegram' => [
        'driver' => 'custom',
        'via' => \DenoBY\TelegramLogger\Logger::class,
        'level' => env('LOG_LEVEL', 'error'),
    ],
],

'stack' => [
    'driver' => 'stack',
    'channels' => ['daily', 'telegram'],
    'ignore_exceptions' => false,
],

Log::channel('telegram')->error('Something went wrong!');

'daily' => [
    'driver' => 'daily',
    'path' => storage_path('logs/laravel.log'),
    'level' => 'debug',
    'tap' => [\DenoBY\TelegramLogger\Tap::class],
],

'channels' => [
    'tg_payments' => [
        'driver' => 'custom',
        'via' => \DenoBY\TelegramLogger\Logger::class,
        'level' => 'info',
        'thread_id' => env('TELEGRAM_PAYMENTS_THREAD_ID'),
    ],

    'tg_queues' => [
        'driver' => 'custom',
        'via' => \DenoBY\TelegramLogger\Logger::class,
        'level' => 'warning',
        'thread_id' => env('TELEGRAM_QUEUES_THREAD_ID'),
    ],
],

// both overridden
'tap' => [\DenoBY\TelegramLogger\Tap::class.':42,warning'],

// only thread_id (level falls back to global)
'tap' => [\DenoBY\TelegramLogger\Tap::class.':42'],

// only level (thread_id falls back to global)
'tap' => [\DenoBY\TelegramLogger\Tap::class.':,warning'],

// no overrides — uses global config
'tap' => [\DenoBY\TelegramLogger\Tap::class],

use DenoBY\TelegramLogger\Facades\Telegram;
use DenoBY\TelegramLogger\Message;

// Simple message
Telegram::sendMessageToChat(
    new Message('Hello from Laravel!'),
    config('telegram-logger.chat_id')
);

// With topic (thread)
Telegram::sendMessageToChat(
    new Message('Hello!'),
    config('telegram-logger.chat_id'),
    threadId: config('telegram-logger.thread_id')
);

use DenoBY\TelegramLogger\Message;

// Create message with photos
$message = (new Message('Check out these photos!'))
    ->addPhoto('https://example.com/image1.jpg')
    ->addPhoto('https://example.com/image2.jpg');

// Append/prepend text
$message = (new Message('Main content'))
    ->prependText('Header:')
    ->appendText('Footer');

use DenoBY\TelegramLogger\Facades\Telegram;

Telegram::sendDocument(
    filePath: '/path/to/document.pdf',
    chatId: config('telegram-logger.chat_id'),
    caption: 'Here is your document',
    threadId: config('telegram-logger.thread_id')
);

// config/telegram-logger.php

return [
    // Bot token from @BotFather
    'token' => env('TELEGRAM_LOG_TOKEN'),

    // Chat/Group/Channel ID
    'chat_id' => env('TELEGRAM_LOG_CHAT_ID'),

    // Topic ID (for supergroups with topics)
    'thread_id' => env('TELEGRAM_LOG_THREAD_ID'),

    // App info for log messages
    'app_name' => env('APP_NAME', 'Laravel'),
    'app_url' => env('APP_URL'),
    'environment' => env('APP_ENV', 'production'),
    'deploy_branch' => env('DEPLOY_BRANCH'),

    // Exceptions to ignore completely
    'ignore_exceptions' => [
        // \Symfony\Component\Mailer\Exception\TransportException::class,
    ],

    // Exceptions to log without stack trace
    'ignore_stack_trace_for' => [
        // \App\Exceptions\CustomException::class,
    ],

    // Maximum message length (Telegram limit is 4096)
    'max_message_length' => 3040,

    // Include authenticated user info
    '
bash
php artisan vendor:publish --provider="DenoBY\TelegramLogger\ServiceProvider"