Skip to content

Commit f1cf93e

Browse files
committed
Update Readme
1 parent 72e3cd9 commit f1cf93e

File tree

1 file changed

+101
-8
lines changed

1 file changed

+101
-8
lines changed

README.md

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# WhatsApp notification channel for Laravel
23

34
[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/whatsapp.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/whatsapp)
@@ -26,19 +27,111 @@ This package makes it easy to send notifications using [WhatsApp Cloud API](http
2627

2728
## Installation
2829

29-
Please also include the steps for any third-party service setup that's required for this package.
30+
You can install the package via composer:
31+
```
32+
composer require laravel-notification-channels/whatsapp
33+
```
34+
### Setting up the WhatsApp Cloud API
35+
36+
Create a new Meta application and get your Whatsapp `application token` and `phone number id` following the ["Get Started"](https://developers.facebook.com/docs/whatsapp/cloud-api/get-started?locale=en_US#set-up-developer-assets) guide. Place them inside your `.env` file. To load them, add this to your `config/services.php` file:
37+
```php
38+
<?php
39+
40+
return [
41+
42+
/*
43+
|--------------------------------------------------------------------------
44+
| Third Party Services
45+
|--------------------------------------------------------------------------
46+
|
47+
| This file is for storing the credentials for third party services such
48+
| as Mailgun, Postmark, AWS and more. This file provides the de facto
49+
| location for this type of information, allowing packages to have
50+
| a conventional file to locate the various service credentials.
51+
|
52+
*/
53+
54+
// Other third-party config...
55+
56+
'whatsapp' => [
57+
'from-phone-number-id' => env('WHATSAPP_FROM_PHONE_NUMBER_ID'),
58+
'token' => env('WHATSAPP_TOKEN'),
59+
],
60+
61+
];
62+
```
3063

31-
### Setting up the WhatsApp service
64+
## Usage
3265

33-
Optionally include a few steps how users can set up the service.
66+
The Whatsapp API only allows you to start conversations if you send a template message. This means that you will only be able to send template notifications from this package.
3467

35-
## Usage
68+
Whatsapp forces you to configure your templates before using them. You can learn how to configure your templates by following Meta's official guide on ["How to create templates"](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates).
3669

37-
Some code examples, make it clear how to use the package
70+
### WhatsApp templates sections
3871

39-
### Available Message methods
72+
A template is divided into 4 sections: header, body, footer and buttons. The header, body and buttons accept variables. The footer doesn't accept variables. You can only send variables from this package for the header and body. Support for sending variables for buttons has not yet been added.
4073

41-
A list of all available options
74+
### Components
75+
76+
You have available several components that can be used to add context (variables) to your templates. The different components can be created with the component factory:
77+
78+
```php
79+
<?php
80+
81+
use NotificationChannels\WhatsApp\Component;
82+
83+
Component::currency($amount, $code = 'EUR');
84+
Component::dateTime($dateTime, $format = 'Y-m-d H:i:s');
85+
Component::document($link);
86+
Component::image($link);
87+
Component::video($link);
88+
Component::text($text);
89+
```
90+
Components supported by Whatsapp template sections:
91+
92+
- Header: image, video, document and text (the text accepts currency, datetime and text variables)
93+
- Body: currency, datetime and text
94+
95+
### Send a notification
96+
97+
To use this package, you need to create a notification class, like `MovieTicketPaid` from the example below, in your Laravel application. Make sure to check out [Laravel's documentation](https://laravel.com/docs/master/notifications) for this process.
98+
99+
```php
100+
<?php
101+
102+
namespace App\Notifications;
103+
104+
use Illuminate\Notifications\Notification;
105+
use NotificationChannels\WhatsApp\Component;
106+
use NotificationChannels\WhatsApp\WhatsAppChannel;
107+
use NotificationChannels\WhatsApp\WhatsAppTemplate;
108+
109+
class MovieTicketPaid extends Notification
110+
{
111+
/**
112+
* Get the notification's delivery channels.
113+
*
114+
* @param mixed $notifiable
115+
* @return array
116+
*/
117+
public function via($notifiable)
118+
{
119+
return [WhatsAppChannel::class];
120+
}
121+
122+
public function toWhatsapp($notifiable)
123+
{
124+
return WhatsAppTemplate::create()
125+
->name('sample_movie_ticket_confirmation') // Name of your configured template
126+
->header(Component::image('https://lumiere-a.akamaihd.net/v1/images/image_c671e2ee.jpeg'))
127+
->body(Component::text('Star Wars'))
128+
->body(Component::dateTime(new \DateTimeImmutable))
129+
->body(Component::text('Star Wars'))
130+
->body(Component::text('5'))
131+
->to('34676010101');
132+
}
133+
}
134+
```
42135

43136
## Changelog
44137

@@ -52,7 +145,7 @@ $ composer test
52145

53146
## Security
54147

55-
If you discover any security related issues, please email alex@netflie.es instead of using the issue tracker.
148+
If you discover any security related issues, please email hola@netflie.es instead of using the issue tracker.
56149

57150
## Contributing
58151

0 commit comments

Comments
 (0)