Skip to content

Commit 64e148b

Browse files
committed
Initial Commit
0 parents  commit 64e148b

23 files changed

+1141
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/.scrutinizer.yml export-ignore
10+
/tests export-ignore

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
build
3+
composer.phar
4+
composer.lock

.scrutinizer.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true
19+

.styleci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
preset: laravel
2+
3+
linting: true

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: php
2+
3+
php:
4+
- 5.6
5+
- 7.0
6+
7+
env:
8+
matrix:
9+
- COMPOSER_FLAGS="--prefer-lowest"
10+
- COMPOSER_FLAGS=""
11+
12+
before_script:
13+
- travis_retry composer self-update
14+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
15+
16+
script:
17+
- phpunit --coverage-text --coverage-clover=coverage.clover
18+
19+
after_script:
20+
- php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
All Notable changes to `facebook` will be documented in this file
4+
5+
## 1.0.0 - 201X-XX-XX
6+
7+
- initial release

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54+
55+
**Happy coding**!

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) Syed Irfaq R. <[email protected]>
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Facebook Notifications Channel for Laravel 5.3 [WIP]
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/facebook.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/facebook)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
5+
[![Build Status](https://img.shields.io/travis/laravel-notification-channels/facebook/master.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/facebook)
6+
[![StyleCI](https://styleci.io/repos/xxxxxx/shield)](https://styleci.io/repos/xxxxxx)
7+
[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/xxxxxxxxxx.svg?style=flat-square)](https://insight.sensiolabs.com/projects/xxxxxxxxxx)
8+
[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/facebook.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/facebook)
9+
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/facebook.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/facebook)
10+
11+
This package makes it easy to send notifications using [Facebook](https://developers.facebook.com/docs/messenger-platform/product-overview) with Laravel 5.3.
12+
13+
## Contents
14+
15+
- [Installation](#installation)
16+
- [Setting up the Facebook service](#setting-up-the-facebook-service)
17+
- [Usage](#usage)
18+
- [Available Message methods](#available-message-methods)
19+
- [Changelog](#changelog)
20+
- [Testing](#testing)
21+
- [Security](#security)
22+
- [Contributing](#contributing)
23+
- [Credits](#credits)
24+
- [License](#license)
25+
26+
27+
## Installation
28+
29+
You can install the package via composer:
30+
31+
``` bash
32+
composer require laravel-notification-channels/facebook
33+
```
34+
35+
You must install the service provider:
36+
37+
```php
38+
// config/app.php
39+
'providers' => [
40+
NotificationChannels\Facebook\FacebookServiceProvider::class,
41+
];
42+
```
43+
44+
## Setting up your Facebook Bot
45+
46+
Follow the [Getting Started](https://developers.facebook.com/docs/messenger-platform/quickstart) guide and get a page token.
47+
48+
Then, configure your Facebook Page Token:
49+
50+
```php
51+
// config/services.php
52+
'facebook' => [
53+
'page-token' => env('FACEBOOK_PAGE_TOKEN', 'YOUR BOT TOKEN HERE')
54+
]
55+
```
56+
57+
## Usage
58+
59+
You can now use the channel in your `via()` method inside the Notification class.
60+
61+
``` php
62+
use NotificationChannels\Facebook\FacebookChannel;
63+
use NotificationChannels\Facebook\FacebookMessage;
64+
use NotificationChannels\Facebook\Attachment\Button;
65+
use NotificationChannels\Facebook\NotificationType;
66+
67+
use Illuminate\Notifications\Notification;
68+
69+
class InvoicePaid extends Notification
70+
{
71+
public function via($notifiable)
72+
{
73+
return [FacebookChannel::class];
74+
}
75+
76+
public function toFacebook($notifiable)
77+
{
78+
$url = url('/invoice/' . $this->invoice->id);
79+
80+
return FacebookMessage::create()
81+
->to($this->user->fb_messenger_user_id) // Optional
82+
->text('One of your invoices has been paid!')
83+
->notificationType(NotificationType::REGULAR) // Optional
84+
->buttons([
85+
Button::create('View Invoice', $url)->isTypeWebUrl(),
86+
Button::create('Call Us for Support!', '+1(212)555-2368')->isTypePhoneNumber(),
87+
Button::create('Start Chatting', ['invoice_id' => $this->invoice->id])->isTypePostback() // Custom payload sent back to your server
88+
]); // Buttons are optional as well.
89+
}
90+
}
91+
```
92+
93+
Here's a screenshot preview of the above notification on Facebook Messenger:
94+
95+
![Laravel Facebook Notification Example](https://cloud.githubusercontent.com/assets/1915268/17666125/58d6b66c-631c-11e6-9380-0400832b2e48.png)
96+
97+
### Routing a message
98+
99+
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:
100+
101+
``` php
102+
...
103+
/**
104+
* Route notifications for the Facebook channel.
105+
*
106+
* @return int
107+
*/
108+
public function routeNotificationForFacebook()
109+
{
110+
return $this->fb_messenger_user_id;
111+
}
112+
...
113+
```
114+
115+
### Available Message methods
116+
117+
- `to($userIdOrPhoneNumber)`: (string) Recipient's page-scoped User ID or Phone number of with the 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.
118+
- `text('')`: (string) Notification message.
119+
- `buttons($buttons = [])`: (array) An array of "Call to Action" buttons (Created using `NotificationChannels\Facebook\Attachment\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.
120+
- `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.
121+
122+
### Available Button methods
123+
124+
- `title('')`: (string) Button Title.
125+
- `data('')`: (string) Button Data - It can be a web url, postback data or a formated phone number.
126+
- `type('')`: (string) Button Type - `web_url`, `postback` or `phone_number`.
127+
- `isTypeWebUrl()`: Helper method to create a `web_url` type button.
128+
- `isTypePhoneNumber()`: Helper method to create a `phone_number` type button.
129+
- `isTypePostback()`: Helper method to create a `postback` type button.
130+
131+
## Contributing
132+
133+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
134+
135+
## Credits
136+
137+
- [Syed Irfaq R.](https://github.com/irazasyed)
138+
- [All Contributors](../../contributors)
139+
140+
## License
141+
142+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

0 commit comments

Comments
 (0)