PHPackages                             laravel-notification-channels/facebook - 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. laravel-notification-channels/facebook

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

laravel-notification-channels/facebook
======================================

Facebook Notifications Channel for Laravel

0.3.0(4y ago)15279.4k↓25.9%31[1 issues](https://github.com/laravel-notification-channels/facebook/issues)MITPHPPHP ^7.2 || ^8.0CI passing

Since Aug 15Pushed 4mo ago18 watchersCompare

[ Source](https://github.com/laravel-notification-channels/facebook)[ Packagist](https://packagist.org/packages/laravel-notification-channels/facebook)[ Docs](https://github.com/laravel-notification-channels/facebook)[ RSS](/packages/laravel-notification-channels-facebook/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (8)Dependencies (5)Versions (9)Used By (0)

Facebook Notifications Channel for Laravel
==========================================

[](#facebook-notifications-channel-for-laravel)

[![Join PHP Chat](https://camo.githubusercontent.com/29f67fb2289efd1ecede6eaa41c82be0e3f93dbf5a8193f1f0fc1b4f33719fa7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f536c61636b2d504850253230436861742d3563366161612e7376673f7374796c653d666c61742d737175617265266c6f676f3d736c61636b266c6162656c436f6c6f723d344131353442)](https://phpchat.co/?ref=laravel-channel-facebook)[![Chat on Telegram](https://camo.githubusercontent.com/c793b6d887d39dac6773fa734b19b63fb1b8a392156528c648c2564000509eba/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4050485043686174436f2d3243413545302e7376673f7374796c653d666c61742d737175617265266c6f676f3d74656c656772616d266c6162656c3d54656c656772616d)](https://t.me/PHPChatCo)[![Latest Version on Packagist](https://camo.githubusercontent.com/f8a34ec18289e0bec9294eae5f058075d5880841af2aeed5c4f77dbb59d62c3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c732f66616365626f6f6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravel-notification-channels/facebook)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/20bf466399671eaadc96db42701e41ba9f6aa18b0c445c74acbacd6e0ede0f09/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c732f66616365626f6f6b2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/laravel-notification-channels/facebook)[![Total Downloads](https://camo.githubusercontent.com/7a389fe16fbd64392eecbef865dc6d2bde8f71430859f9cb5004fc3988fdd29a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c732f66616365626f6f6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravel-notification-channels/facebook)

This package makes it easy to send notifications using the [Facebook Messenger](https://developers.facebook.com/docs/messenger-platform/product-overview) with Laravel.

Contents
--------

[](#contents)

- [Installation](#installation)
    - [Setting up your Facebook Bot](#setting-up-your-facebook-bot)
- [Usage](#usage)
    - [Available Message methods](#available-message-methods)
    - [Available Button methods](#available-button-methods)
    - [Available Card methods](#available-card-methods)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

You can install the package via composer:

```
composer require laravel-notification-channels/facebook
```

Setting up your Facebook Bot
----------------------------

[](#setting-up-your-facebook-bot)

Follow the [Getting Started](https://developers.facebook.com/docs/messenger-platform/quickstart) guide in order to create a Facebook Messenger app, a Facebook page and a page token, which is connecting both.

Next we need to add this token to our Laravel configurations. Create a new Facebook section inside `config/services.php` and place the page token there:

```
// config/services.php
...
'facebook' => [
    'page-token' => env('FACEBOOK_PAGE_TOKEN', 'YOUR PAGE TOKEN HERE'),

    // Optional - Omit this if you want to use default version.
    'version'    => env('FACEBOOK_GRAPH_API_VERSION', '4.0')

    // Optional - If set, the appsecret_proof will be sent to verify your page-token.
    'app-secret' => env('FACEBOOK_APP_SECRET', '')
],
...
```

Usage
-----

[](#usage)

Let's take an invoice-paid-notification as an example. You can now use the Facebook channel in your `via()` method, inside the InvoicePaid class. The `to($userId)` method defines the Facebook user, you want to send the notification to.

Based on the details you add (text, attachments etc.) will determine automatically the type of message to be sent. For example if you only add `text()` then it will be a basic message; using `attach()` will turn this into a attachment message. Having `buttons` or `cards` will change this to the `Button Template` and `Generic Template` respectivily

```
use NotificationChannels\Facebook\FacebookChannel;
use NotificationChannels\Facebook\FacebookMessage;
use NotificationChannels\Facebook\Components\Button;
use NotificationChannels\Facebook\Enums\NotificationType;

use Illuminate\Notifications\Notification;

class InvoicePaid extends Notification
{
    public function via($notifiable)
    {
        return [FacebookChannel::class];
    }

    public function toFacebook($notifiable)
    {
        $url = url('/invoice/' . $this->invoice->id);

        return FacebookMessage::create()
            ->to($notifiable->fb_messenger_user_id) // Optional
            ->text('One of your invoices has been paid!')
            ->isUpdate() // Optional
            ->isTypeRegular() // Optional
            // Alternate method to provide the notification type.
            // ->notificationType(NotificationType::REGULAR) // Optional
            ->buttons([
                Button::create('View Invoice', $url)->isTypeWebUrl(),
                Button::create('Call Us for Support!', '+1(212)555-2368')->isTypePhoneNumber(),
                Button::create('Start Chatting', ['invoice_id' => $this->invoice->id])->isTypePostback() // Custom payload sent back to your server
            ]); // Buttons are optional as well.
    }
}
```

The notification will be sent from your Facebook page, whose page token you have configured earlier. Here's a screenshot preview of the notification inside the chat window.

[![Laravel Facebook Notification Example](https://cloud.githubusercontent.com/assets/1915268/17666125/58d6b66c-631c-11e6-9380-0400832b2e48.png)](https://cloud.githubusercontent.com/assets/1915268/17666125/58d6b66c-631c-11e6-9380-0400832b2e48.png)

#### Message Examples

[](#message-examples)

##### Basic Text Message

[](#basic-text-message)

Send a basic text message to a user

```
return FacebookMessage::create('You have just paid your monthly fee! Thanks')
    ->to($notifiable->fb_messenger_user_id);
```

##### Attachment Message

[](#attachment-message)

Send a file attachment to a user (Example is sending a pdf invoice)

```
return FacebookMessage::create()
    ->attach(AttachmentType::FILE, url('invoices/'.$this->invoice->id))
    ->to($notifiable->fb_messenger_user_id);
```

##### Generic (Card Carousel) Message

[](#generic-card-carousel-message)

Send a set of cards / items to a user displayed in a carousel (Example is sending a set of links). Note you can also add up to three buttons per card

```
return FacebookMessage::create()
    ->to($notifiable->fb_messenger_user_id) // Optional
    ->cards([
        Card::create('Card No.1 Title')
            ->subtitle('An item description')
            ->url('items/'.$this->item[0]->id)
            ->image('items/'.$this->item[0]->id.'/image'),

        Card::create('Card No.2 Title')
            ->subtitle('An item description')
            ->url('items/'.$this->item[1]->id)
            ->image('items/'.$this->item[1]->id.'/image')
        // could add buttons using ->buttons($array of Button)
    ]);
```

### Routing a message

[](#routing-a-message)

You can either send the notification by providing with the page-scoped user id (PSID) of the recipient to the `to($userId)` method like shown in the above example or add a `routeNotificationForFacebook()` method in your notifiable model:

```
...
/**
 * Route notifications for the Facebook channel.
 *
 * @return int
 */
public function routeNotificationForFacebook()
{
    return $this->fb_messenger_user_id;
}
...
```

### Available Message methods

[](#available-message-methods)

- `to($recipient, $type)`: (string|array) Recipient's page-scoped User `id`, `phone_number`, `user_ref`, `post_id` or `comment_id` (as one of the supported types - Use `Enums\RecipientType` to make it easier). Phone number supported format `+1(212)555-2368`. **NOTE:** Sending a message to phone numbers requires the `pages_messaging_phone_number` permission. Refer [docs](https://developers.facebook.com/docs/messenger-platform/send-api-reference#phone_number) for more information.
- `text('')`: (string) Notification message.
- `isResponse()`: Set `messaging_type` as `RESPONSE`.
- `isUpdate()`: (default) Set `messaging_type` as `UPDATE`.
- `isMessageTag($messageTag)`: (string) Set `messaging_type` as `MESSAGE_TAG`, you can refer and make use of the `NotificationChannels\Facebook\Enums\MessageTag` to make it easier to work with the message tag.
- `attach($attachment_type, $url)`: (AttachmentType, string) An attachment type (IMAGE, AUDIO, VIDEO, FILE) and the url of this attachment
- `buttons($buttons = [])`: (array) An array of "Call to Action" buttons (Created using `NotificationChannels\Facebook\Components\Button::create()`). You can add up to 3 buttons of one of the following types: `web_url`, `postback` or `phone_number`. See Button methods below for more details.
- `cards($cards = [])`: (array) An array of item cards to be displayed in a carousel (Created using `NotificationChannels\Facebook\Components\Card::create()`). You can add up to 10 cards. See Card methods below for more details.
- `notificationType('')`: (string) Push Notification type: `REGULAR` will emit a sound/vibration and a phone notification; `SILENT_PUSH` will just emit a phone notification, `NO_PUSH` will not emit either. You can make use of `NotificationType::REGULAR`, `NotificationType::SILENT_PUSH` and `NotificationType::NO_PUSH` to make it easier to work with the type. This is an optional method, defaults to `REGULAR` type.
- `imageAspectRatio('')`: (string) Image Aspect Ratio if Card with `image_url` present. You can use of `ImageAspectRatioType::SQUARE` or `ImageAspectRatioType::HORIZONTAL`. This is an optional method, defaults to `ImageAspectRatioType::HORIZONTAL` aspect ratio (image should be 1.91:1).
- `isTypeRegular()`: Helper method to create a notification type: `REGULAR`.
- `isTypeSilentPush()`: Helper method to create a notification type: `SILENT_PUSH`.
- `isTypeNoPush()`: Helper method to create a notification type: `NO_PUSH`.

### Available Button methods

[](#available-button-methods)

- `title('')`: (string) Button Title.
- `data('')`: (string) Button Data - It can be a web url, postback data or a formated phone number.
- `type('')`: (string) Button Type - `web_url`, `postback` or `phone_number`. Use `ButtonType` enumerator for guaranteeing valid values
- `isTypeWebUrl()`: Helper method to create a `web_url` type button.
- `isTypePhoneNumber()`: Helper method to create a `phone_number` type button.
- `isTypePostback()`: Helper method to create a `postback` type button.

### Available Card methods

[](#available-card-methods)

- `title('')`: (string) Card Title.
- `subtitle('')`: (string) Card Subtitle.
- `url('')`: (string) Card Item Url.
- `image('')`: (string) Card Image Url. Image ratio should be 1.91:1
- `buttons($buttons = [])`: (array) An array of "Call to Action" buttons (Created using `NotificationChannels\Facebook\Components\Button::create()`). You can add up to 3 buttons of one of the following types: `web_url`, `postback` or `phone_number`. See Button methods above for more details.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Irfaq Syed](https://github.com/irazasyed)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance51

Moderate activity, may be stable

Popularity48

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 80.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~282 days

Recently: every ~206 days

Total

8

Last Release

1633d ago

PHP version history (3 changes)0.0.1PHP &gt;=5.6.4

0.0.4PHP ^7.2

0.2.1PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20937037?v=4)[Laravel Notification Channels](/maintainers/laravel-notification-channels)[@laravel-notification-channels](https://github.com/laravel-notification-channels)

---

Top Contributors

[![irazasyed](https://avatars.githubusercontent.com/u/1915268?v=4)](https://github.com/irazasyed "irazasyed (78 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (6 commits)")[![dostrog](https://avatars.githubusercontent.com/u/948264?v=4)](https://github.com/dostrog "dostrog (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![Mirnaxvb](https://avatars.githubusercontent.com/u/6596602?v=4)](https://github.com/Mirnaxvb "Mirnaxvb (1 commits)")[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (1 commits)")[![oyed](https://avatars.githubusercontent.com/u/172114265?v=4)](https://github.com/oyed "oyed (1 commits)")[![pschocke](https://avatars.githubusercontent.com/u/26882621?v=4)](https://github.com/pschocke "pschocke (1 commits)")[![casperboone](https://avatars.githubusercontent.com/u/15815208?v=4)](https://github.com/casperboone "casperboone (1 commits)")[![themsaid](https://avatars.githubusercontent.com/u/4332182?v=4)](https://github.com/themsaid "themsaid (1 commits)")[![davidpiesse](https://avatars.githubusercontent.com/u/800650?v=4)](https://github.com/davidpiesse "davidpiesse (1 commits)")[![enniel](https://avatars.githubusercontent.com/u/19760944?v=4)](https://github.com/enniel "enniel (1 commits)")[![henokv](https://avatars.githubusercontent.com/u/17256654?v=4)](https://github.com/henokv "henokv (1 commits)")

---

Tags

facebookfacebook-apifacebook-botfacebook-graph-apifacebook-messengerfacebook-messenger-botfacebook-notificationfacebook-pagehacktoberfestlaravellaravel-5-packagelaravel-6-packagelaravel-7-packagelaravel-8-packagelaravel-notification-channelslaravel-notificationsnotificationsphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laravel-notification-channels-facebook/health.svg)

```
[![Health](https://phpackages.com/badges/laravel-notification-channels-facebook/health.svg)](https://phpackages.com/packages/laravel-notification-channels-facebook)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M166](/packages/spatie-laravel-health)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[laravel-notification-channels/expo

Expo Notifications Channel for Laravel

67628.6k1](/packages/laravel-notification-channels-expo)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k20](/packages/fleetbase-core-api)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
