Skip to content

Commit 3897666

Browse files
committed
Revise README. Add new methods and update examples.
1 parent d85f677 commit 3897666

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

README.md

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ Next we need to add this token to our Laravel configurations. Create a new Faceb
3939
// config/services.php
4040
...
4141
'facebook' => [
42-
'page-token' => env('FACEBOOK_PAGE_TOKEN', 'YOUR PAGE TOKEN HERE')
42+
'page-token' => env('FACEBOOK_PAGE_TOKEN', 'YOUR PAGE TOKEN HERE'),
43+
44+
// Optional - Omit this if you want to use default version.
45+
'version' => env('FACEBOOK_GRAPH_API_VERSION', '4.0')
4346
],
4447
...
4548
```
@@ -51,7 +54,7 @@ You can now use the Facebook channel in your `via()` method, inside the InvoiceP
5154

5255
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
5356

54-
``` php
57+
```php
5558
use NotificationChannels\Facebook\FacebookChannel;
5659
use NotificationChannels\Facebook\FacebookMessage;
5760
use NotificationChannels\Facebook\Components\Button;
@@ -73,7 +76,10 @@ class InvoicePaid extends Notification
7376
return FacebookMessage::create()
7477
->to($this->user->fb_messenger_user_id) // Optional
7578
->text('One of your invoices has been paid!')
76-
->notificationType(NotificationType::REGULAR) // Optional
79+
->isUpdate() // Optional
80+
->isTypeRegular() // Optional
81+
// Alternate method to provide the notification type.
82+
// ->notificationType(NotificationType::REGULAR) // Optional
7783
->buttons([
7884
Button::create('View Invoice', $url)->isTypeWebUrl(),
7985
Button::create('Call Us for Support!', '+1(212)555-2368')->isTypePhoneNumber(),
@@ -88,36 +94,43 @@ The notification will be sent from your Facebook page, whose page token you have
8894
![Laravel Facebook Notification Example](https://cloud.githubusercontent.com/assets/1915268/17666125/58d6b66c-631c-11e6-9380-0400832b2e48.png)
8995

9096
#### Message Examples
97+
9198
##### Basic Text Message
99+
92100
Send a basic text message to a user
93101
```php
94102
return FacebookMessage::create('You have just paid your monthly fee! Thanks')
95-
->to($this->user->fb_messenger_id);
103+
->to($this->user->fb_messenger_id);
96104
```
97105
##### Attachment Message
106+
98107
Send a file attachment to a user (Example is sending a pdf invoice)
108+
99109
```php
100110
return FacebookMessage::create()
101-
->attach(AttachmentType::FILE, url('invoices/'.$this->invoice->id))
102-
->to($this->user->fb_messenger_id);
111+
->attach(AttachmentType::FILE, url('invoices/'.$this->invoice->id))
112+
->to($this->user->fb_messenger_id);
103113
```
104114

105115
##### Generic (Card Carousel) Message
116+
106117
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
118+
107119
```php
108120
return FacebookMessage::create()
109-
->cards([
110-
Card::create('Card No.1 Title')
111-
->subtitle('An item description')
112-
->url('items/'.$this->item[0]->id)
113-
->image('items/'.$this->item[0]->id.'/image'),
114-
Card::create('Card No.2 Title')
115-
->subtitle('An item description')
116-
->url('items/'.$this->item[1]->id)
117-
->image('items/'.$this->item[1]->id.'/image')
118-
//could add buttons using ->buttons($array of Button)
119-
])
120-
->to($this->user->fb_messenger_id);
121+
->to($this->user->fb_messenger_id) // Optional
122+
->cards([
123+
Card::create('Card No.1 Title')
124+
->subtitle('An item description')
125+
->url('items/'.$this->item[0]->id)
126+
->image('items/'.$this->item[0]->id.'/image'),
127+
128+
Card::create('Card No.2 Title')
129+
->subtitle('An item description')
130+
->url('items/'.$this->item[1]->id)
131+
->image('items/'.$this->item[1]->id.'/image')
132+
// could add buttons using ->buttons($array of Button)
133+
]);
121134
```
122135

123136
### Routing a message
@@ -140,12 +153,18 @@ public function routeNotificationForFacebook()
140153

141154
### Available Message methods
142155

143-
- `to($pageScopedIdOrPhoneNumber, $type)`: (string) Recipient's page-scoped User `id`, `phone_number`, `user_ref`, `post_id` or `comment_id` (as one of the supported types). 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.
156+
- `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.
144157
- `text('')`: (string) Notification message.
158+
- `isResponse()`: Set `messaging_type` as `RESPONSE`.
159+
- `isUpdate()`: (default) Set `messaging_type` as `UPDATE`.
160+
- `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.
145161
- `attach($attachment_type, $url)`: (AttachmentType, string) An attachment type (IMAGE, AUDIO, VIDEO, FILE) and the url of this attachment
146162
- `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.
147163
- `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.
148164
- `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.
165+
- `isTypeRegular()`: Helper method to create a notification type: `REGULAR`.
166+
- `isTypeSilentPush()`: Helper method to create a notification type: `SILENT_PUSH`.
167+
- `isTypeNoPush()`: Helper method to create a notification type: `NO_PUSH`.
149168

150169
### Available Button methods
151170

0 commit comments

Comments
 (0)