PHPackages                             sindaniel/laravel-telegram-error-reporter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. sindaniel/laravel-telegram-error-reporter

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

sindaniel/laravel-telegram-error-reporter
=========================================

Laravel package to report application errors to Telegram

v1.0.0(11mo ago)03MITPHPPHP ^8.1

Since Jun 17Pushed 11mo agoCompare

[ Source](https://github.com/sindaniel/laravel-telegram-error-reporter)[ Packagist](https://packagist.org/packages/sindaniel/laravel-telegram-error-reporter)[ RSS](/packages/sindaniel-laravel-telegram-error-reporter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Laravel Telegram Error Reporter
===============================

[](#laravel-telegram-error-reporter)

A Laravel package that automatically reports your application's 500 errors to Telegram.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require sindaniel/laravel-telegram-error-reporter
```

Publish the configuration file:

```
php artisan vendor:publish --provider="Sindaniel\LaravelTelegramErrorReporter\TelegramErrorReporterServiceProvider" --tag="config"
```

Configuration
-------------

[](#configuration)

### 1. Create a Telegram Bot

[](#1-create-a-telegram-bot)

1. Open Telegram and search for `@BotFather`
2. Send `/newbot` and follow the instructions
3. Save the token provided by BotFather

### 2. Get the Chat ID

[](#2-get-the-chat-id)

To get your personal Chat ID:

1. Search for `@userinfobot` in Telegram
2. Send `/start` and you'll get your Chat ID

For a group:

1. Add your bot to the group
2. Send any message in the group
3. Visit: `https://api.telegram.org/bot/getUpdates`
4. Look for the `chat.id` in the response

### 3. Environment Variables

[](#3-environment-variables)

Add these variables to your `.env` file:

```
TELEGRAM_ERROR_BOT_TOKEN=your_bot_token_here
TELEGRAM_ERROR_CHAT_ID=your_chat_id_here
TELEGRAM_ERROR_ENABLED=true
```

Usage
-----

[](#usage)

### Basic Configuration in bootstrap/app.php

[](#basic-configuration-in-bootstrapappphp)

Replace your current code with this:

```
->withExceptions(function (Exceptions $exceptions) {
    $exceptions->report(function (Throwable $e) {
        // Report to Telegram
        app(\Sindaniel\LaravelTelegramErrorReporter\TelegramErrorReporter::class)
            ->report($e, $errorData);
    });
});
```

### Test the Configuration

[](#test-the-configuration)

You can test if your configuration works correctly:

```
use Sindaniel\LaravelTelegramErrorReporter\TelegramErrorReporterFacade as TelegramError;

$result = TelegramError::test();
dd($result);
```

Advanced Configuration
----------------------

[](#advanced-configuration)

The configuration file `config/telegram-error-reporter.php` contains the following options:

### Environment Filters

[](#environment-filters)

```
'environments' => ['production'], // Only report in production
```

### Rate Limiting

[](#rate-limiting)

```
'rate_limit_per_minute' => 5, // Maximum 5 errors per minute
```

### Custom Message Template

[](#custom-message-template)

```
'message_template' => "🚨 *Error in {app_name}*\n\n" .
                     "**Environment:** {environment}\n" .
                     "**Message:** {message}\n" .
                     "**File:** {file}:{line}\n" .
                     "**URL:** {url}\n" .
                     "**IP:** {ip}\n" .
                     "**Time:** {timestamp}",
```

Available variables:

- `{app_name}` - Application name
- `{environment}` - Current environment (production, local, etc.)
- `{message}` - Error message
- `{file}` - File where the error occurred
- `{line}` - Line where the error occurred
- `{url}` - URL where the error occurred
- `{ip}` - User's IP address
- `{user_agent}` - Browser's user agent
- `{timestamp}` - Date and time of the error
- `{session_id}` - Session ID

Example Artisan Command for Testing
-----------------------------------

[](#example-artisan-command-for-testing)

Create an Artisan command to test the reporter:

```
php artisan make:command TestTelegramError
```

```
