Introduction to Jengo Notifications
jengo/notifications is an enterprise-grade, multi-channel notification delivery engine for CodeIgniter 4 and the Jengo Framework.
It allows you to deliver notifications across diverse communication channels—Transactional Email, SMS, In-App Database Alerts, WebPush, Firebase Cloud Messaging (FCM), Slack Webhooks, Secure Outbound Webhooks, and Real-Time SSE/WebSocket Broadcasts—using a single declarative notification class.
Key Features
- Unified Multi-Channel Architecture: Deliver to one or many channels simultaneously (
mail,database,sms,push,slack,webhook,broadcast) from a single notification class. - First-Class SMS Providers: Zero-dependency pure-PHP cURL drivers for SMSGate (SMS Gateway for Android™ local server & cloud API), Africa's Talking (with E.164 phone normalization), Twilio, Log, and Null drivers.
- In-App Database Alerts: Comprehensive schema with action links, button labels, severity levels (
info,success,warning,danger), and entity scopes (unreadNotifications(),markAsRead()). - Responsive Email Themes: Built-in responsive HTML & plain-text templates (
default,minimal,dark) with Outlook VML bulletproof action buttons and markdown formatting. - Mobile & Web Push: Dual driver support for WebPush (browser push via VAPID keys) and Firebase Cloud Messaging (FCM v1) HTTP API.
- Security-First Webhooks: Outbound webhooks featuring automatic HMAC-SHA256 signature generation and timestamp headers (
X-Signature,X-Timestamp) for replay protection. - Slack Block Kit: Fluent layout builder for Slack webhooks with sections, buttons, fields, and context blocks.
- Asynchronous Background Delivery: Implement the
ShouldQueuecontract to automatically dispatch notifications to background queue workers viajengo/queuesorcodeigniter4/queue. - On-Demand Routing: Send notifications to non-persisted ad-hoc recipients using
Notification::route('channel', 'target')->notify(...). - Testing Doubles: Instant
Notification::fake()with rich PHPUnit assertions (assertSentTo,assertNotSentTo,assertSentOnChannel,assertSentTimes,assertNothingSent). - Spark CLI Tooling: Automated scaffolding and diagnostic commands (
jengo:install notifications,make:notification,notifications:table,notifications:test).
Quick Example
php
namespace App\Notifications;
use Jengo\Notifications\Messages\MailMessage;
use Jengo\Notifications\Messages\DatabaseMessage;
use Jengo\Notifications\Messages\SmsMessage;
use Jengo\Notifications\Notification;
class InvoicePaid extends Notification
{
public function __construct(public array $invoice)
{
parent::__construct();
}
public function via(object $notifiable): array
{
return ['mail', 'database', 'sms'];
}
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage())
->subject("Invoice Paid #{$this->invoice['id']}")
->greeting("Hello {$notifiable->name},")
->line("We have received your payment of \${$this->invoice['amount']}.")
->action('View Receipt', site_url("invoices/{$this->invoice['id']}"));
}
public function toDatabase(object $notifiable): DatabaseMessage
{
return (new DatabaseMessage())
->title('Invoice Paid')
->message("Payment received for invoice #{$this->invoice['id']}")
->link(site_url("invoices/{$this->invoice['id']}"))
->level('success');
}
public function toSms(object $notifiable): SmsMessage
{
return (new SmsMessage("Your invoice #{$this->invoice['id']} is paid."))
->link(site_url("invoices/{$this->invoice['id']}"));
}
}Dispatching to any notifiable entity:
php
$user->notify(new InvoicePaid($invoice));