You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+101-8Lines changed: 101 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
1
2
# WhatsApp notification channel for Laravel
2
3
3
4
[](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
26
27
27
28
## Installation
28
29
29
-
Please also include the steps for any third-party service setup that's required for this package.
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:
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.
34
67
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).
36
69
37
-
Some code examples, make it clear how to use the package
70
+
### WhatsApp templates sections
38
71
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.
40
73
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:
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
0 commit comments