laravel-notification-channels / Facebook

Licence: mit
📨 Facebook Notifications Channel for Laravel

Projects that are alternatives of or similar to Facebook

messenger
💬 A PHP library for Facebook Messenger
Stars: ✭ 53 (-55.83%)
Mutual labels:  facebook, facebook-messenger-bot, facebook-messenger, facebook-api
Facebook-Auto-Pilot
Automate common Facebook activities such as posting to groups and pages walls. Effortlessly post to multiple groups or pages.
Stars: ✭ 126 (+5%)
Mutual labels:  facebook, facebook-messenger-bot, facebook-messenger, facebook-api
facebook-messenger
Go (GoLang) package for Facebook Messenger API and Chat bot
Stars: ✭ 62 (-48.33%)
Mutual labels:  facebook, facebook-messenger-bot, facebook-messenger, facebook-api
Facebooktoolkit
a tool to get Facebook data, and some Facebook bots, and extra tools found on Facebook Toolkit ++.
Stars: ✭ 227 (+89.17%)
Mutual labels:  facebook-api, facebook-messenger-bot, facebook
Telegram
✈️ Telegram Notifications Channel for Laravel
Stars: ✭ 450 (+275%)
Mutual labels:  hacktoberfest, laravel, laravel-5-package
Laravel Gamp
📊 Laravel Google Analytics Measurement Protocol Package
Stars: ✭ 271 (+125.83%)
Mutual labels:  hacktoberfest, laravel, laravel-5-package
Restfb
RestFB is a simple and flexible Facebook Graph API client written in Java.
Stars: ✭ 681 (+467.5%)
Mutual labels:  facebook-api, facebook-messenger, facebook
Fb Messenger Cli
fb-messenger-cli, console Facebook messenger
Stars: ✭ 665 (+454.17%)
Mutual labels:  facebook-api, facebook-messenger, facebook
Fbchat
Facebook Chat (Messenger) for Python
Stars: ✭ 995 (+729.17%)
Mutual labels:  facebook-messenger-bot, hacktoberfest, facebook-messenger
Chatblocks
Declarative Messenger chatbot framework
Stars: ✭ 48 (-60%)
Mutual labels:  facebook-messenger-bot, facebook-messenger, facebook
Fluent Facebook
A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax
Stars: ✭ 49 (-59.17%)
Mutual labels:  facebook-api, laravel, laravel-5-package
Health
Laravel Health Panel
Stars: ✭ 1,774 (+1378.33%)
Mutual labels:  hacktoberfest, laravel, notifications
Laravel Facebook Ads
Facebook & Instagram Ads API for Laravel
Stars: ✭ 87 (-27.5%)
Mutual labels:  facebook-api, laravel, facebook
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+493.33%)
Mutual labels:  hacktoberfest, laravel, laravel-5-package
Notifier
NO LIBRARIES socket per page bridge for your Laravel application. (CLIENT PART INCLUDED)
Stars: ✭ 57 (-52.5%)
Mutual labels:  laravel, laravel-5-package, notifications
Devil
Devil is a tool that is basically made for facebook to Hack target accounts , BruteForce Attack , grab friendlist accounts , yahoo chacker , Facbook Friend information gathering tool , auto likes reactions & much more i hope you enjoy this tool i'm not responsible if you use this tool for any illegal purpose
Stars: ✭ 88 (-26.67%)
Mutual labels:  facebook-api, facebook-messenger-bot, facebook
Facebook Export
Tools to help administer your Facebook groups
Stars: ✭ 96 (-20%)
Mutual labels:  facebook-api, facebook
Sharedchamber
Android Secure SharedPreferences Using Facebook Conceal Encryption
Stars: ✭ 96 (-20%)
Mutual labels:  hacktoberfest, facebook
Generators
Laravel File Generators with config and publishable stubs
Stars: ✭ 102 (-15%)
Mutual labels:  hacktoberfest, laravel
Collect
A Collections-only split from Laravel's Illuminate Support
Stars: ✭ 1,433 (+1094.17%)
Mutual labels:  hacktoberfest, laravel

Facebook Notifications Channel for Laravel

Latest Version on Packagist Software License SensioLabsInsight Quality Score Total Downloads

This package makes it easy to send notifications using the Facebook Messenger with Laravel.

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/facebook

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:

// 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

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($this->user->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

Message Examples

Basic Text Message

Send a basic text message to a user

return FacebookMessage::create('You have just paid your monthly fee! Thanks')
    ->to($this->user->fb_messenger_id);
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($this->user->fb_messenger_id);
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($this->user->fb_messenger_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

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

  • 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 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.
  • 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 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

  • 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

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].