{"id":20696047,"url":"https://github.com/laravel-notification-channels/facebook","last_synced_at":"2025-04-04T15:11:36.670Z","repository":{"id":10420713,"uuid":"65683997","full_name":"laravel-notification-channels/facebook","owner":"laravel-notification-channels","description":"📨 Facebook Notifications Channel for Laravel","archived":false,"fork":false,"pushed_at":"2024-03-12T20:35:59.000Z","size":115,"stargazers_count":151,"open_issues_count":0,"forks_count":32,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-03-28T14:11:09.634Z","etag":null,"topics":["facebook","facebook-api","facebook-bot","facebook-graph-api","facebook-messenger","facebook-messenger-bot","facebook-notification","facebook-page","hacktoberfest","laravel","laravel-5-package","laravel-6-package","laravel-7-package","laravel-8-package","laravel-notification-channels","laravel-notifications","notifications","php"],"latest_commit_sha":null,"homepage":"https://laravel-notification-channels.com/facebook/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laravel-notification-channels.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-14T19:59:24.000Z","updated_at":"2024-04-26T19:12:05.000Z","dependencies_parsed_at":"2024-06-19T00:19:28.554Z","dependency_job_id":"bfa469e2-544c-48f6-b2ab-73fb855e4412","html_url":"https://github.com/laravel-notification-channels/facebook","commit_stats":{"total_commits":75,"total_committers":15,"mean_commits":5.0,"dds":0.5333333333333333,"last_synced_commit":"0a8c7f6e2af5aeceaf2477770c780979bc835d94"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Ffacebook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Ffacebook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Ffacebook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Ffacebook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laravel-notification-channels","download_url":"https://codeload.github.com/laravel-notification-channels/facebook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198469,"owners_count":20900081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["facebook","facebook-api","facebook-bot","facebook-graph-api","facebook-messenger","facebook-messenger-bot","facebook-notification","facebook-page","hacktoberfest","laravel","laravel-5-package","laravel-6-package","laravel-7-package","laravel-8-package","laravel-notification-channels","laravel-notifications","notifications","php"],"created_at":"2024-11-17T00:12:21.560Z","updated_at":"2025-04-04T15:11:36.647Z","avatar_url":"https://github.com/laravel-notification-channels.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Facebook Notifications Channel for Laravel\n\n[![Join PHP Chat][ico-phpchat]][link-phpchat]\n[![Chat on Telegram][ico-telegram]][link-telegram]\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![Total Downloads][ico-downloads]][link-packagist]\n\nThis package makes it easy to send notifications using the [Facebook Messenger](https://developers.facebook.com/docs/messenger-platform/product-overview) with Laravel.\n\n## Contents\n\n- [Installation](#installation)\n\t- [Setting up your Facebook Bot](#setting-up-your-facebook-bot)\n- [Usage](#usage)\n\t- [Available Message methods](#available-message-methods)\n\t- [Available Button methods](#available-button-methods)\n\t- [Available Card methods](#available-card-methods)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require laravel-notification-channels/facebook\n```\n\n## Setting up your Facebook Bot\n\nFollow 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.\n\nNext 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:\n\n```php\n// config/services.php\n...\n'facebook' =\u003e [\n    'page-token' =\u003e env('FACEBOOK_PAGE_TOKEN', 'YOUR PAGE TOKEN HERE'),\n    \n    // Optional - Omit this if you want to use default version.\n    'version'    =\u003e env('FACEBOOK_GRAPH_API_VERSION', '4.0')\n    \n    // Optional - If set, the appsecret_proof will be sent to verify your page-token.\n    'app-secret' =\u003e env('FACEBOOK_APP_SECRET', '')\n],\n...\n```\n\n## Usage\n\nLet's take an invoice-paid-notification as an example.\nYou 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.\n\nBased 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\n\n```php\nuse NotificationChannels\\Facebook\\FacebookChannel;\nuse NotificationChannels\\Facebook\\FacebookMessage;\nuse NotificationChannels\\Facebook\\Components\\Button;\nuse NotificationChannels\\Facebook\\Enums\\NotificationType;\n\nuse Illuminate\\Notifications\\Notification;\n\nclass InvoicePaid extends Notification\n{\n    public function via($notifiable)\n    {\n        return [FacebookChannel::class];\n    }\n\n    public function toFacebook($notifiable)\n    {\n        $url = url('/invoice/' . $this-\u003einvoice-\u003eid);\n\n        return FacebookMessage::create()\n            -\u003eto($notifiable-\u003efb_messenger_user_id) // Optional\n            -\u003etext('One of your invoices has been paid!')\n            -\u003eisUpdate() // Optional\n            -\u003eisTypeRegular() // Optional\n            // Alternate method to provide the notification type.\n            // -\u003enotificationType(NotificationType::REGULAR) // Optional\n            -\u003ebuttons([\n                Button::create('View Invoice', $url)-\u003eisTypeWebUrl(),\n                Button::create('Call Us for Support!', '+1(212)555-2368')-\u003eisTypePhoneNumber(),\n                Button::create('Start Chatting', ['invoice_id' =\u003e $this-\u003einvoice-\u003eid])-\u003eisTypePostback() // Custom payload sent back to your server\n            ]); // Buttons are optional as well.\n    }\n}\n```\n\nThe 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.\n\n![Laravel Facebook Notification Example](https://cloud.githubusercontent.com/assets/1915268/17666125/58d6b66c-631c-11e6-9380-0400832b2e48.png)\n\n#### Message Examples\n\n##### Basic Text Message\n\nSend a basic text message to a user\n```php\nreturn FacebookMessage::create('You have just paid your monthly fee! Thanks')\n    -\u003eto($notifiable-\u003efb_messenger_user_id);\n```\n##### Attachment Message\n\nSend a file attachment to a user (Example is sending a pdf invoice)\n\n```php\nreturn FacebookMessage::create()\n    -\u003eattach(AttachmentType::FILE, url('invoices/'.$this-\u003einvoice-\u003eid))\n    -\u003eto($notifiable-\u003efb_messenger_user_id);\n```\n\n##### Generic (Card Carousel) Message\n\nSend 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\n\n```php\nreturn FacebookMessage::create()\n    -\u003eto($notifiable-\u003efb_messenger_user_id) // Optional\n    -\u003ecards([\n        Card::create('Card No.1 Title')\n            -\u003esubtitle('An item description')\n            -\u003eurl('items/'.$this-\u003eitem[0]-\u003eid)\n            -\u003eimage('items/'.$this-\u003eitem[0]-\u003eid.'/image'),\n        \n        Card::create('Card No.2 Title')\n            -\u003esubtitle('An item description')\n            -\u003eurl('items/'.$this-\u003eitem[1]-\u003eid)\n            -\u003eimage('items/'.$this-\u003eitem[1]-\u003eid.'/image')\n        // could add buttons using -\u003ebuttons($array of Button)\n    ]); \n```\n\n### Routing a message\n\nYou 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:\n\n```php\n...\n/**\n * Route notifications for the Facebook channel.\n *\n * @return int\n */\npublic function routeNotificationForFacebook()\n{\n    return $this-\u003efb_messenger_user_id;\n}\n...\n```\n\n### Available Message methods\n\n- `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.\n- `text('')`: (string) Notification message.\n- `isResponse()`: Set `messaging_type` as `RESPONSE`.\n- `isUpdate()`: (default) Set `messaging_type` as `UPDATE`.\n- `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.\n- `attach($attachment_type, $url)`: (AttachmentType, string) An attachment type (IMAGE, AUDIO, VIDEO, FILE) and the url of this attachment\n- `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.\n- `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.\n- `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.\n- `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).\n- `isTypeRegular()`: Helper method to create a notification type: `REGULAR`.\n- `isTypeSilentPush()`: Helper method to create a notification type: `SILENT_PUSH`.\n- `isTypeNoPush()`: Helper method to create a notification type: `NO_PUSH`.\n\n### Available Button methods\n\n- `title('')`: (string) Button Title.\n- `data('')`: (string) Button Data - It can be a web url, postback data or a formated phone number.\n- `type('')`: (string) Button Type - `web_url`, `postback` or `phone_number`. Use `ButtonType` enumerator for guaranteeing valid values\n- `isTypeWebUrl()`: Helper method to create a `web_url` type button.\n- `isTypePhoneNumber()`: Helper method to create a `phone_number` type button.\n- `isTypePostback()`: Helper method to create a `postback` type button.\n\n### Available Card methods\n\n- `title('')`: (string) Card Title.\n- `subtitle('')`: (string) Card Subtitle.\n- `url('')`: (string) Card Item Url.\n- `image('')`: (string) Card Image Url. Image ratio should be 1.91:1\n- `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.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Credits\n\n- [Irfaq Syed][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-phpchat]: https://img.shields.io/badge/Slack-PHP%20Chat-5c6aaa.svg?style=flat-square\u0026logo=slack\u0026labelColor=4A154B\n[ico-telegram]: https://img.shields.io/badge/@PHPChatCo-2CA5E0.svg?style=flat-square\u0026logo=telegram\u0026label=Telegram\n[ico-version]: https://img.shields.io/packagist/v/laravel-notification-channels/facebook.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/facebook.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/laravel-notification-channels/facebook.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/laravel-notification-channels/facebook.svg?style=flat-square\n\n[link-phpchat]: https://phpchat.co/?ref=laravel-channel-facebook\n[link-telegram]: https://t.me/PHPChatCo\n[link-repo]: https://github.com/laravel-notification-channels/facebook\n[link-packagist]: https://packagist.org/packages/laravel-notification-channels/facebook\n[link-scrutinizer]: https://scrutinizer-ci.com/g/laravel-notification-channels/facebook/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/laravel-notification-channels/facebook\n[link-author]: https://github.com/irazasyed\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravel-notification-channels%2Ffacebook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaravel-notification-channels%2Ffacebook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravel-notification-channels%2Ffacebook/lists"}