WhatsApp Notifications Channel for Laravel using GoWa as a Worker
This package makes it easy to send notifications using WhatsApp Business API over GoWa Worker with Laravel 8.0+
- Installation
- Setting up the WhatsApp Worker
- Usage
- Changelog
- Testing
- Security
- Contributing
- Credits
- License
You can install the package via composer:
composer require aasumitro/whatsapp-notification-channel
Then, configure your WhatsApp Worker API URL:
// config/services.php
'whatsapp-notification-service' => [
'service_api_url' => env('WHATSAPP_SERVICE_URL', 'YOUR WORKER API_URL HERE')
],
Then, register whatsapp notification service provider:
// config/services.php
'providers' => [
....
\NotificationChannels\WhatsApp\WhatsAppServiceProvider::class
],
use the view component
<x-whatsapp-account></x-whatsapp-account>
You can now use the channel in your via() method inside the Notification class.
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\WhatsApp\WhatsAppChannel;
use NotificationChannels\WhatsApp\WhatsAppMessage;
class WhatsappSendTextMessageNotification extends Notification
{
use Queueable;
private $message;
public function __construct(string $message)
{
$this->message = $message;
}
public function via($notifiable): array
{
return [WhatsAppChannel::class];
}
public function toWhatsapp($notifiable): WhatsAppMessage
{
return WhatsAppMessage::create()
->to($notifiable->msisdn)
->content($this->message);
}
}
You can either send the notification by providing with the Destination number of the recipient to the to($msisdn) method like shown in the previous examples or add a routeNotificationForWhatsApp() method in your notifiable model:
/**
* Route notifications for the WhatsApp channel.
*
* @return int
*/
public function routeNotificationForWhatsApp()
{
return $this->whatsapp_phone_number;
}
- WhatsAppFile (audio, document, image, video) prior
- WhatsAppLocation
Please see CHANGELOG for more information what has changed recently.
$ composer test
or
$ ./vendor/bin/phpunit ./packages/whatsapp-notification-channel/tests
If you discover any security related issues, please email hello@aasumitro.id instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.