Search by

mphpmaster / laravel-nova-sanadwa-whatsapp

mPhpMaster

WhatsApp for Laravel and Nova: SanadWA / UltraMsg drivers, notification channel with template fallback, signed webhooks, message log, conversations, contacts and a diagnostics page. Arabic and English.

Package info

github.com/mPhpMaster/laravel-nova-sanadwa-whatsapp

pkg:composer/mphpmaster/laravel-nova-sanadwa-whatsapp

Statistics

Installs: 21

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-27 19:28 UTC

This package is auto-updated.

Last update: 2026-11-27 19:32:46 UTC


README

WhatsApp for Laravel 11/12 and Nova 5, built around the SanadWA WhatsApp Business API (UltraMsg and a generic gateway also work).

  • Sending: text, images, approved templates and verification codes, through one client.
  • 24-hour window handled: when free text is refused because the customer hasn't written in 24 hours, the message goes out as an approved template instead. That's the event's own template if the notification has one, otherwise the general one.
  • Notification channel: use via(['whatsapp']) and add an optional whatsappTemplate().
  • Signed webhook: receives customer messages and delivery statuses (sent, delivered, read, failed). Out-of-order updates are ignored, retries are de-duplicated, and every delivery is stored for debugging.
  • Message log, conversations, contacts:
    • One conversation per number, with an unread count and the 24h window state.
    • Customers who write in become contacts automatically.
    • Contacts import from and export to CSV.
  • Diagnostics page:
    • Shows the settings check, API health, balance and sender numbers.
    • Lists templates with their review status.
    • Sends a real test message and shows the full error.
    • Runs a signed webhook self-test.
    • Lists recent failures and the raw webhooks received.
  • Nova 5: resources, a «Send WhatsApp» action you can add to any resource, menu items with an unread badge, and the diagnostics page inside Nova. Nova is optional.
  • Languages: Arabic (RTL) and English.

Nothing is tied to one site. Template names, the site name, phone rules, tables and permissions all come from config or from your own settings store.

Install

composer require mphpmaster/laravel-nova-sanadwa-whatsapp
php artisan vendor:publish --tag=whatsapp-config
php artisan migrate

The migrations skip tables that already exist. With spatie/laravel-permission they also create the package permissions.

Configure

WHATSAPP_DRIVER=sanadwa
WHATSAPP_TOKEN=pk_live_...
WHATSAPP_PHONE_NUMBER_ID=...
WHATSAPP_WEBHOOK_SECRET=whsec_...
WHATSAPP_MESSAGE_TEMPLATE=general_update     # {{1}} site name, {{2}} text
WHATSAPP_IMAGE_TEMPLATE=general_update_image # image header, {{1}} site name, {{2}} caption
WHATSAPP_OTP_TEMPLATE=login_code             # authentication, {{1}} code
WHATSAPP_COUNTRY_CODE=966                    # local numbers 05XXXXXXXX → +9665XXXXXXXX
WHATSAPP_MOBILE_PREFIX=5

To keep the settings in your database instead of .env:

use MPhpMaster\NovaSanadwaWhatsApp\WhatsApp;

// AppServiceProvider::boot()
WhatsApp::resolveSettingsUsing(fn () => setting('whatsapp'));   // any non-empty key overrides config
WhatsApp::siteNameUsing(fn () => setting('site.name'));

Register the webhook URL https://your-site/webhooks/sanadwa in the SanadWA console. You can change the path with whatsapp.routes.webhook.

Keep the site name out of the fixed template text and pass it as a value. That way one SanadWA account can serve several sites with the same approved templates.

Send

use MPhpMaster\NovaSanadwaWhatsApp\Facades\WhatsApp;

WhatsApp::send('0551234567', 'Your order has shipped');
WhatsApp::sendImage('+966551234567', 'https://example.com/receipt.png', 'Your receipt');
WhatsApp::sendTemplate('+966551234567', 'order_status_update', ['A-1001', 'My Shop', 'Shipped']);
WhatsApp::sendCode('+966551234567', '123456', 'Your code is 123456'); // the log hides the code

Every call returns true or false and never throws. The reason for a failure is in app(WhatsAppClient::class)->lastError, translated, and in the log.

Notifications

use MPhpMaster\NovaSanadwaWhatsApp\Concerns\HasWhatsAppTemplate;

class OrderStatusChanged extends Notification
{
    use HasWhatsAppTemplate;

    public function via($notifiable) { return ['mail', 'whatsapp']; }

    public function toWhatsApp($notifiable): string
    {
        return "Order {$this->order->number} is now {$this->status}";
    }

    // Used only when the customer's 24h window is closed. "{site}" becomes the site name.
    public function whatsappTemplate($notifiable): ?array
    {
        return $this->whatsappTemplatePayload('order_status_update', [$this->order->number, '{site}', $this->status]);
    }
}

The recipient comes from routeNotificationForWhatsapp(), or from the notifiable's phone. To rename a template without code, set whatsapp.templates.order_status_update.

Nova

When Nova is installed, the resources (conversations, log, contacts) and the diagnostics page register themselves. For a custom main menu, call NovaWhatsApp::menuSection() or NovaWhatsApp::menuItems(). To add the send action to your own resources:

use MPhpMaster\NovaSanadwaWhatsApp\Nova\Actions\SendWhatsApp;

SendWhatsApp::make()->canSee(fn ($request) => $request->user()->can('whatsapp.send'));

It sends to the model's phone, or to its user's phone.

Permissions

Each resource uses {ability}{Model} permissions:

  • viewAnyWhatsappLog
  • updateWhatsappConversation
  • createContact, and so on.

There are also two standalone permissions, whatsapp.send and whatsapp.diagnostics, both configurable. The migrations create all of them when spatie/laravel-permission is installed. To grant them on migrate to every role that has a given permission, set whatsapp.permissions.grant_to_roles_with. Super-admins still pass through your Gate::before.

Phone numbers

Support\Phone stores numbers as +E164. It accepts local spellings for the configured country (05…, 5…, 009665…, 9660…) and Arabic-Indic digits.

Tests

composer test

License

MIT

بالعربي

باكج واتساب لـ Laravel وNova، مبنية على بوابة سند (SanadWA).

  • الإرسال: نص وصور وقوالب معتمدة وأكواد تحقق.
  • نافذة الـ 24 ساعة: إذا ما راسلك العميل خلالها، تتحول الرسالة تلقائيًا لقالب معتمد.
  • الويب هوك: موقّع، ويسجّل ردود العملاء وحالة التسليم.
  • في Nova: سجل الواتساب، والمحادثات، وجهات الاتصال (استيراد وتصدير CSV)، وصفحة تشخيص كاملة.
  • عامة: كل الإعدادات من ملف config أو من إعدادات موقعك، وما فيها اسم موقع ثابت. اسم الموقع يجي كمتغيّر وقت الإرسال، فنفس قوالب سند تخدم أكثر من موقع.