C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • WebSockets
  • Task Scheduling
  • Queues
  • Job Batches
  • Caching
  • Events
  • Broadcasting
  • Notifications
  • SMS Channels
  • File Storage
  • Payment
  • Search
  • Security
  • Security Comparison
  • Performance
  • HTTP/2 Support
  • Deployment

Notifications

CanxJS provides a unified API for sending notifications across a variety of delivery channels, including email, database, SMS, and Slack.

Creating Notifications

To create a notification, use the make:notification command:

bash
bun run canx make:notification InvoicePaid

This class contains a via method defining the delivery channels and methods to format the message for each channel.

typescript
import { Notification, type Notifiable, type NotificationChannel } from 'canxjs';

export class InvoicePaid extends Notification {
  constructor(public invoiceId: string) {
    super();
  }

  via(notifiable: Notifiable): NotificationChannel[] {
    return ['mail', 'database'];
  }

  toMail(notifiable: Notifiable) {
    return {
      subject: 'Invoice Paid',
      html: `<p>Your invoice ${this.invoiceId} has been paid.</p>`
    };
  }

  toDatabase(notifiable: Notifiable) {
    return {
      invoice_id: this.invoiceId,
      amount: 100
    };
  }
}

Sending Notifications

You can send notifications using the notify helper or by using the Notifiable trait on your User model.

typescript
import { notify } from 'canxjs';
import { InvoicePaid } from './notifications/InvoicePaid';

// Using the helper
await notify(user, new InvoicePaid('INV-1001'));

// Using the User model (if using Notifiable mixin)
await user.notify(new InvoicePaid('INV-1001'));

Database Notifications

The database channel stores notification information in a database table. You can access these notifications to display them in your UI.

typescript
const notifications = await Notification.where('notifiable_id', user.id).get();

Mail Notifications

When using the mail channel, CanxJS attempts to send an email to the address defined in the email property of your notifiable entity.