PHP code example of iperamuna / laravel-telegram-log-buttons
1. Go to this page and download the library: Download iperamuna/laravel-telegram-log-buttons 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/ */
iperamuna / laravel-telegram-log-buttons example snippets
'bot_token' => env('TELEGRAM_LOG_BOT_TOKEN'),
'chat_id' => env('TELEGRAM_LOG_CHAT_ID'),
'channels' => [
// ... other channels
'telegram' => [
'driver' => 'monolog',
'handler' => \Iperamuna\TelegramLog\Logging\TelegramButtonHandler::class,
'level' => env('LOG_LEVEL', 'debug'),
],
],
use Illuminate\Support\Facades\Log;
Log::channel('telegram')
->buttons()
->url('View Dashboard', 'https://example.com/dashboard')
->callback('Approve', 'approve:123')
->newRow()
->callback('Reject', 'reject:123')
->info('New user registration
Log::channel('telegram')
->buttons()
->url('View Order', 'https://example.com/orders/123')
->callback('Approve', 'order:approve:123')
->callback('Reject', 'order:reject:123')
->newRow()
->callback('Contact Customer', 'contact:customer:456')
->warning('Order #123
Log::channel('telegram')
->addButton('View Details', 'https://example.com/details')
->info('Payment received for order #123');
Log::channel('telegram')
->addButtons([
['text' => 'View', 'url' => 'https://example.com/view'],
['text' => 'Edit', 'callback_data' => 'edit:123'],
['text' => 'Delete', 'callback_data' => 'delete:123'],
])
->error('Critical error detected in order processing');
use Iperamuna\TelegramLog\Logging\MacroableLogger;
$logger = new MacroableLogger('telegram');
$logger->pushHandler(new \Iperamuna\TelegramLog\Logging\TelegramButtonHandler());
$logger->buttons()
->callback('Retry', 'retry:task:456')
->error('Task execution failed');
->url('Open Website', 'https://example.com')
->callback('Approve', 'approve:123')
->callback('Reject', 'reject:123')
'template' => env('TELEGRAM_LOG_TEMPLATE', 'telegram-log::standard'),
'channels' => [
'telegram' => [
'driver' => 'monolog',
'handler' => \Iperamuna\TelegramLog\Logging\TelegramButtonHandler::class,
'handler_with' => [
'template' => 'telegram-log::minimal',
// You can also override other parameters:
// 'botToken' => env('TELEGRAM_CUSTOM_BOT_TOKEN'),
// 'chatId' => env('TELEGRAM_CUSTOM_CHAT_ID'),
// 'parseMode' => 'Markdown',
],
'level' => env('LOG_LEVEL', 'debug'),
],
'telegram-alerts' => [
'driver' => 'monolog',
'handler' => \Iperamuna\TelegramLog\Logging\TelegramButtonHandler::class,
'handler_with' => [
'template' => 'telegram-log::standard',
'chatId' => env('TELEGRAM_ALERTS_CHAT_ID'),
],
'level' => 'critical',
],
],
// In config/telegram-log.php
'template' => 'telegram-log::custom',
// Or per channel
'handler_with' => [
'template' => 'telegram-log::custom',
],
class BanUserCallback extends AbstractTelegramCallbackHandler
{
protected function handleParsed(array $update, string $action, string $payload): void
{
// Your logic here - $action and $payload are already parsed!
// $action = "ban_user"
// $payload = "5" (from "ban_user:5")
}
}
'map' => [
'ban_user' => \App\Telegram\Callbacks\BanUserCallback::class,
],
use Iperamuna\TelegramLog\Facades\TelegramCallbacks;
// Register a closure handler
TelegramCallbacks::on('approve', function (array $update, string $data) {
// Handle the callback
$parts = explode(':', $data, 2);
$payload = $parts[1] ?? '';
// Your logic here
});
// Register a class handler
TelegramCallbacks::on('ban_user', \App\Telegram\Callbacks\BanUserCallback::class);
// Get all registered handlers
$allHandlers = TelegramCallbacks::all();
'health' => [
'enabled' => env('TELEGRAM_LOG_HEALTH_ENABLED', false),
'path' => env('TELEGRAM_LOG_HEALTH_PATH', '/telegram/log/health'),
'secret' => env('TELEGRAM_LOG_HEALTH_SECRET', null),
],
bash
php artisan telegram-log:install
bash
php artisan vendor:publish --provider="Iperamuna\\TelegramLog\\TelegramLogServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Iperamuna\\TelegramLog\\TelegramLogServiceProvider" --tag="views"
bash
php artisan telegram-log:list-callbacks
bash
php artisan telegram-log:install