Unified, multi-channel notification system — mail, SMS, push, in-app, Slack and webhook — dispatched asynchronously through the Momo queue.
🇷🇺 Документация на русском: README.ru.md
composer require momo-framework/notificationsNotificationsServiceProvider is auto-discovered. It binds
NotificationDispatcherInterface, the six channels, their transports (in-memory
by default), the throttler and the in-app store.
Make a model notifiable:
use Momo\Notifications\Contracts\NotifiableInterface;
use Momo\Notifications\Support\Notifiable;
final class User implements NotifiableInterface
{
use Notifiable;
public function __construct(private string $id, private string $email) {}
public function notificationKey(): string { return $this->id; }
protected function notificationRoutes(): array
{
return ['mail' => $this->email];
}
}Write a notification — implement the builder for each channel it supports:
use Momo\Notifications\Contracts\NotifiableInterface;
use Momo\Notifications\Contracts\NotificationInterface;
use Momo\Notifications\Messages\{MailMessage, RoutesToMail};
final class OrderShipped implements NotificationInterface, RoutesToMail
{
public function __construct(private string $orderId) {}
public function via(NotifiableInterface $n): array { return ['mail']; }
public function toMail(NotifiableInterface $n): MailMessage
{
return new MailMessage(
subject: 'Your order shipped',
body: "Order {$this->orderId} is on its way.",
locale: $n->preferredLocale(),
);
}
}Dispatch it:
$dispatcher->send($user, new OrderShipped('o-42')); // queued (async)
$dispatcher->sendNow($user, new OrderShipped('o-42')); // inline (sync)| Channel | Builder interface | Message | Routed by |
|---|---|---|---|
mail |
RoutesToMail |
MailMessage |
routeNotificationFor('mail') |
sms |
RoutesToSms |
SmsMessage |
routeNotificationFor('sms') |
push |
RoutesToPush |
PushMessage |
routeNotificationFor('push') |
broadcast |
RoutesToBroadcast |
BroadcastMessage |
notificationKey() (in-app inbox) |
slack |
RoutesToSlack |
SlackMessage |
routeNotificationFor('slack') |
webhook |
RoutesToWebhook |
WebhookMessage |
routeNotificationFor('webhook') |
A channel skips a notification that does not implement its builder, or a recipient with no address for it.
Implement ShouldThrottleInterface to cap deliveries per recipient per window;
the dispatcher consults the throttler before each channel send and emits a
NotificationThrottled event when it suppresses one.
AGPL-3.0-or-later.