PHPackages                             mortogo321/laravel-notify - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. mortogo321/laravel-notify

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

mortogo321/laravel-notify
=========================

A Laravel package for sending notifications and alerts to multiple providers

2.0.0(3mo ago)1246MITPHPPHP ^8.2CI passing

Since Oct 20Pushed 2mo agoCompare

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

READMEChangelogDependencies (6)Versions (3)Used By (0)

Laravel Notify
==============

[](#laravel-notify)

[![Latest Version on Packagist](https://camo.githubusercontent.com/64fbfc7bcd5bc4a5b96606c3d3c235eb28bc308fde5b980be2c5e8ca59e65fdc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f72746f676f3332312f6c61726176656c2d6e6f746966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mortogo321/laravel-notify)[![Tests](https://github.com/mortogo321/laravel-notify/actions/workflows/tests.yml/badge.svg)](https://github.com/mortogo321/laravel-notify/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/76e07d64ebe607db91855e817f0dddc5f020b0e2f532d70e4c9fef00b0d95872/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f72746f676f3332312f6c61726176656c2d6e6f746966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mortogo321/laravel-notify)[![GitHub License](https://camo.githubusercontent.com/14aad9ae79137436e1f4b08007366b6ed9545cd0467fdb9497896d5a2239f5c7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6f72746f676f3332312f6c61726176656c2d6e6f746966792e7376673f7374796c653d666c61742d737175617265)](https://github.com/mortogo321/laravel-notify/blob/main/LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/792e4f6f7625ac6cbd0ba4207704af782cf70d294f4c847c7d7e49819a4fa06e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d6f72746f676f3332312f6c61726176656c2d6e6f746966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mortogo321/laravel-notify)

A flexible Laravel package for sending notifications and alerts to multiple providers including Slack, Discord, Telegram, LINE Notify, and Email.

Features
--------

[](#features)

- **Multiple Providers**: Support for Slack, Discord, Telegram, LINE Notify, and Email notifications
- **Easy Provider Switching**: Seamlessly switch between providers with a simple API
- **Send to Multiple Providers**: Broadcast notifications to multiple providers at once
- **Channel/Group Helpers**: Built-in methods to list channels, get chat IDs, and more
- **Highly Configurable**: Customize each provider with extensive options
- **Extensible Architecture**: Easily add custom notification providers
- **Facade Support**: Clean and intuitive facade for easy integration
- **Type-Safe**: Built with modern PHP 8.2+ strict types

Requirements
------------

[](#requirements)

- PHP 8.2, 8.3, or 8.4
- Laravel 11.x or 12.x

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

[](#installation)

Install the package via Composer:

```
composer require mortogo321/laravel-notify
```

Publish the configuration file:

```
php artisan vendor:publish --tag=notify-config
```

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

[](#configuration)

Add your notification provider credentials to your `.env` file:

```
NOTIFY_DEFAULT_PROVIDER=slack

# Slack Configuration
NOTIFY_SLACK_ENABLED=true
NOTIFY_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
NOTIFY_SLACK_USERNAME="Laravel Notify"
NOTIFY_SLACK_ICON=:bell:
NOTIFY_SLACK_CHANNEL=#general

# Discord Configuration
NOTIFY_DISCORD_ENABLED=true
NOTIFY_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR/WEBHOOK/URL
NOTIFY_DISCORD_USERNAME="Laravel Notify"

# Telegram Configuration
NOTIFY_TELEGRAM_ENABLED=true
NOTIFY_TELEGRAM_BOT_TOKEN=your-bot-token
NOTIFY_TELEGRAM_CHAT_ID=your-chat-id
NOTIFY_TELEGRAM_PARSE_MODE=HTML

# LINE Notify Configuration
NOTIFY_LINE_ENABLED=true
NOTIFY_LINE_ACCESS_TOKEN=your-line-notify-access-token

# Email Configuration
NOTIFY_EMAIL_ENABLED=true
NOTIFY_EMAIL_TO=admin@example.com
NOTIFY_EMAIL_FROM=noreply@example.com
NOTIFY_EMAIL_FROM_NAME="Laravel Notify"
NOTIFY_EMAIL_SUBJECT="Laravel Notification"
```

### Getting Provider Credentials

[](#getting-provider-credentials)

**Slack**: Get your webhook URL from  (Incoming Webhooks)

**Discord**: Server Settings &gt; Integrations &gt; Webhooks &gt; New Webhook

**Telegram**: Message `@BotFather` on Telegram, create a bot, then use the helper methods below to get your chat ID

**LINE Notify**: Generate a personal access token at

**Email**: Uses Laravel's built-in mail system (configure in `config/mail.php`)

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Using the default provider:

```
use Mortogo321\LaravelNotify\Facades\Notify;

// Send a simple notification
Notify::send('Hello, this is a test notification!');
```

### Using Specific Provider

[](#using-specific-provider)

```
// Send to Slack
Notify::provider('slack')->send('Deployment completed successfully!');

// Send to Discord
Notify::provider('discord')->send('New user registered!');

// Send to Telegram
Notify::provider('telegram')->send('Server CPU usage is high!');

// Send to LINE Notify
Notify::provider('line')->send('Daily report is ready.');

// Send to Email
Notify::provider('email')->send('Monthly report is ready.');
```

### Send to Multiple Providers

[](#send-to-multiple-providers)

```
$result = Notify::sendToMultiple(
    ['slack', 'discord', 'telegram', 'line'],
    'Critical: Database backup failed!'
);

// Returns an array with results from each provider
// [
//     'slack' => ['success' => true, ...],
//     'discord' => ['success' => true, ...],
//     'telegram' => ['success' => false, 'error' => '...'],
//     'line' => ['success' => true, ...],
// ]
```

### Provider Management

[](#provider-management)

```
// Check if provider exists
if (Notify::hasProvider('slack')) {
    Notify::provider('slack')->send('Hello!');
}

// Get all registered providers
$providers = Notify::getProviders(); // ['slack', 'discord', 'telegram', 'line', 'email']

// Get/set default provider
$default = Notify::getDefaultProvider(); // 'slack'
Notify::setDefaultProvider('discord');

// Get configuration
$config = Notify::getConfig(); // All config
$default = Notify::getConfig('default'); // 'slack'
```

Channel &amp; Group ID Helpers
------------------------------

[](#channel--group-id-helpers)

Each provider includes helper methods to retrieve channel IDs, group IDs, and other useful information.

### Slack Helpers

[](#slack-helpers)

```
$slack = Notify::provider('slack');

// Get configured settings
$channel = $slack->getChannel();           // '#general'
$username = $slack->getUsername();         // 'Laravel Notify'
$icon = $slack->getIconEmoji();           // ':bell:'
$webhookUrl = $slack->getWebhookUrl();    // Masked URL for security

// List channels (requires bot token with channels:read scope)
$result = $slack->listChannels('xoxb-your-bot-token');
// [
//     'success' => true,
//     'channels' => [
//         ['id' => 'C1234567890', 'name' => 'general', 'is_private' => false, 'num_members' => 50],
//         ['id' => 'C0987654321', 'name' => 'dev-team', 'is_private' => true, 'num_members' => 10],
//     ],
//     'next_cursor' => '...'
// ]

// Get channel info by ID
$result = $slack->getChannelInfo('xoxb-your-bot-token', 'C1234567890');
// ['success' => true, 'channel' => [...]]
```

### Discord Helpers

[](#discord-helpers)

```
$discord = Notify::provider('discord');

// Get configured settings
$username = $discord->getUsername();       // 'Laravel Notify'
$avatarUrl = $discord->getAvatarUrl();    // Avatar URL
$webhookUrl = $discord->getWebhookUrl();  // Masked URL for security
$webhookId = $discord->getWebhookId();    // '123456789012345678'

// Get webhook info (channel ID, guild ID, etc.)
$info = $discord->getWebhookInfo();
// [
//     'success' => true,
//     'webhook' => [
//         'id' => '123456789012345678',
//         'name' => 'Laravel Notify',
//         'channel_id' => '987654321098765432',
//         'guild_id' => '111222333444555666',
//         'avatar' => '...'
//     ]
// ]

// Shorthand methods
$channelId = $discord->getChannelId();    // '987654321098765432'
$guildId = $discord->getGuildId();        // '111222333444555666'

// List guild channels (requires bot token)
$result = $discord->listGuildChannels('your-bot-token', $guildId);
// [
//     'success' => true,
//     'channels' => [
//         ['id' => '...', 'name' => 'general', 'type' => 0, 'position' => 0],
//         ['id' => '...', 'name' => 'announcements', 'type' => 0, 'position' => 1],
//     ]
// ]
```

### Telegram Helpers

[](#telegram-helpers)

```
$telegram = Notify::provider('telegram');

// Get configured settings
$chatId = $telegram->getChatId();         // '-1001234567890'
$botToken = $telegram->getBotToken();     // Masked token for security
$parseMode = $telegram->getParseMode();   // 'HTML'

// Get bot info
$bot = $telegram->getMe();
// [
//     'success' => true,
//     'bot' => [
//         'id' => 123456789,
//         'first_name' => 'My Bot',
//         'username' => 'my_bot',
//         'can_join_groups' => true,
//         ...
//     ]
// ]

// Get chat info
$chat = $telegram->getChat();  // Uses configured chat_id
$chat = $telegram->getChat('-1009876543210');  // Or specify a different chat
// [
//     'success' => true,
//     'chat' => [
//         'id' => -1001234567890,
//         'type' => 'supergroup',
//         'title' => 'My Group',
//         ...
//     ]
// ]

// Get recent updates to find chat IDs
// First, send a message to your bot, then call:
$updates = $telegram->getUpdates();
// [
//     'success' => true,
//     'updates' => [...],
//     'chats' => [
//         ['id' => 123456789, 'type' => 'private', 'first_name' => 'John', 'username' => 'john_doe'],
//         ['id' => -1001234567890, 'type' => 'supergroup', 'title' => 'My Group'],
//     ]
// ]

// Get chat member count
$count = $telegram->getChatMemberCount();
// ['success' => true, 'count' => 150]

// Get chat administrators
$admins = $telegram->getChatAdministrators();
// ['success' => true, 'administrators' => [...]]

// Webhook management
$telegram->setWebhook('https://your-domain.com/webhook', [
    'secret_token' => 'your-secret',
    'allowed_updates' => ['message', 'callback_query'],
]);
$telegram->deleteWebhook();
$webhookInfo = $telegram->getWebhookInfo();
```

### LINE Notify Helpers

[](#line-notify-helpers)

```
$line = Notify::provider('line');

// Get masked access token
$token = $line->getAccessToken();  // 'test-****67890'

// Check API status
$status = $line->getStatus();
// [
//     'success' => true,
//     'status' => 200,
//     'target_type' => 'USER',
//     'target' => 'John Doe',
// ]
```

### Email Helpers

[](#email-helpers)

```
$email = Notify::provider('email');

// Get configured settings
$to = $email->getTo();                    // 'admin@example.com'
$from = $email->getFrom();                // 'noreply@example.com'
$fromName = $email->getFromName();        // 'Laravel Notify'
$subject = $email->getSubject();          // 'Laravel Notification'
$cc = $email->getCc();                    // CC recipients
$bcc = $email->getBcc();                  // BCC recipients

// Validate email addresses
$isValid = $email->validateEmail('test@example.com');  // true
$isValid = $email->validateEmail('invalid-email');     // false

// Validate multiple emails
$result = $email->validateEmails([
    'valid@example.com',
    'also-valid@test.com',
    'invalid-email',
    'bad@',
]);
// [
//     'valid' => ['valid@example.com', 'also-valid@test.com'],
//     'invalid' => ['invalid-email', 'bad@']
// ]
```

Advanced Options
----------------

[](#advanced-options)

### Slack with Attachments

[](#slack-with-attachments)

```
Notify::provider('slack')->send('Check out this info:', [
    'username' => 'Custom Bot Name',
    'icon_emoji' => ':rocket:',
    'channel' => '#deployments',
    'attachments' => [
        [
            'color' => 'good',
            'title' => 'Deployment Status',
            'text' => 'Successfully deployed to production',
            'fields' => [
                [
                    'title' => 'Environment',
                    'value' => 'Production',
                    'short' => true
                ],
                [
                    'title' => 'Version',
                    'value' => 'v2.1.0',
                    'short' => true
                ]
            ]
        ]
    ]
]);
```

### Slack with Block Kit

[](#slack-with-block-kit)

```
Notify::provider('slack')->send('', [
    'blocks' => [
        [
            'type' => 'section',
            'text' => [
                'type' => 'mrkdwn',
                'text' => '*Deployment Alert* :rocket:'
            ]
        ],
        [
            'type' => 'divider'
        ],
        [
            'type' => 'section',
            'fields' => [
                [
                    'type' => 'mrkdwn',
                    'text' => '*Status:*\nSuccess'
                ],
                [
                    'type' => 'mrkdwn',
                    'text' => '*Environment:*\nProduction'
                ]
            ]
        ]
    ]
]);
```

### Discord with Embeds

[](#discord-with-embeds)

```
Notify::provider('discord')->send('New deployment!', [
    'username' => 'Deploy Bot',
    'embeds' => [
        [
            'title' => 'Deployment Status',
            'description' => 'Successfully deployed to production',
            'color' => 3066993, // Green color
            'fields' => [
                [
                    'name' => 'Environment',
                    'value' => 'Production',
                    'inline' => true
                ],
                [
                    'name' => 'Version',
                    'value' => 'v2.1.0',
                    'inline' => true
                ]
            ],
            'timestamp' => now()->toIso8601String()
        ]
    ]
]);
```

### Telegram with Custom Options

[](#telegram-with-custom-options)

```
Notify::provider('telegram')->send('Alert! Server CPU usage is at 90%', [
    'parse_mode' => 'HTML',
    'disable_notification' => false,
    'reply_markup' => [
        'inline_keyboard' => [
            [
                ['text' => 'View Dashboard', 'url' => 'https://dashboard.example.com']
            ]
        ]
    ]
]);
```

### LINE Notify with Sticker

[](#line-notify-with-sticker)

```
Notify::provider('line')->send('Deployment completed!', [
    'stickerPackageId' => 446,
    'stickerId' => 1988,
]);
```

### LINE Notify with Image

[](#line-notify-with-image)

```
Notify::provider('line')->send('Check this chart:', [
    'imageThumbnail' => 'https://example.com/chart-thumb.png',
    'imageFullsize' => 'https://example.com/chart-full.png',
]);
```

### Email with CC/BCC

[](#email-with-ccbcc)

```
Notify::provider('email')->send('Monthly ReportYour report is ready!', [
    'to' => 'user@example.com',
    'subject' => 'Your Monthly Report',
    'from' => 'reports@example.com',
    'from_name' => 'Report System',
    'cc' => 'manager@example.com',
    'bcc' => 'archive@example.com',
]);
```

Using in Controllers
--------------------

[](#using-in-controllers)

```
