Download the PHP package laravel-notification-channels/facebook without Composer
On this page you can find all versions of the php package laravel-notification-channels/facebook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laravel-notification-channels/facebook
More information about laravel-notification-channels/facebook
Files in laravel-notification-channels/facebook
Package facebook
Short Description Facebook Notifications Channel for Laravel
License MIT
Homepage https://github.com/laravel-notification-channels/facebook
Informations about the package facebook
Facebook Notifications Channel for Laravel
This package makes it easy to send notifications using the Facebook Messenger with Laravel.
Contents
- Installation
- Setting up your Facebook Bot
- Usage
- Available Message methods
- Available Button methods
- Available Card methods
- Contributing
- Credits
- License
Installation
You can install the package via composer:
Setting up your Facebook Bot
Follow the Getting Started 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:
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
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.
Message Examples
Basic Text Message
Send a basic text message to a user
Attachment Message
Send a file attachment to a user (Example is sending a pdf invoice)
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
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:
Available Message methods
to($recipient, $type)
: (string|array) Recipient's page-scoped Userid
,phone_number
,user_ref
,post_id
orcomment_id
(as one of the supported types - UseEnums\RecipientType
to make it easier). Phone number supported format+1(212)555-2368
. NOTE: Sending a message to phone numbers requires thepages_messaging_phone_number
permission. Refer docs for more information.text('')
: (string) Notification message.isResponse()
: Setmessaging_type
asRESPONSE
.isUpdate()
: (default) Setmessaging_type
asUPDATE
.isMessageTag($messageTag)
: (string) Setmessaging_type
asMESSAGE_TAG
, you can refer and make use of theNotificationChannels\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 attachmentbuttons($buttons = [])
: (array) An array of "Call to Action" buttons (Created usingNotificationChannels\Facebook\Components\Button::create()
). You can add up to 3 buttons of one of the following types:web_url
,postback
orphone_number
. See Button methods below for more details.cards($cards = [])
: (array) An array of item cards to be displayed in a carousel (Created usingNotificationChannels\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 ofNotificationType::REGULAR
,NotificationType::SILENT_PUSH
andNotificationType::NO_PUSH
to make it easier to work with the type. This is an optional method, defaults toREGULAR
type.imageAspectRatio('')
: (string) Image Aspect Ratio if Card withimage_url
present. You can use ofImageAspectRatioType::SQUARE
orImageAspectRatioType::HORIZONTAL
. This is an optional method, defaults toImageAspectRatioType::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
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
orphone_number
. UseButtonType
enumerator for guaranteeing valid valuesisTypeWebUrl()
: Helper method to create aweb_url
type button.isTypePhoneNumber()
: Helper method to create aphone_number
type button.isTypePostback()
: Helper method to create apostback
type button.
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:1buttons($buttons = [])
: (array) An array of "Call to Action" buttons (Created usingNotificationChannels\Facebook\Components\Button::create()
). You can add up to 3 buttons of one of the following types:web_url
,postback
orphone_number
. See Button methods above for more details.
Contributing
Please see CONTRIBUTING for details.
Credits
- Irfaq Syed
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of facebook with dependencies
guzzlehttp/guzzle Version ^6.2 || ^7.0
illuminate/notifications Version 5.5 - 9
illuminate/support Version 5.5 - 9