LogoLogo
  • Introduction
  • What's New?
  • Upgrade Guide
  • Getting Started
    • Requirements
    • Installation
  • Defining Channels
    • Configuration
    • Retrieving Channels
  • Creating and Sending Notifications
    • Defining Notifications
    • Notifiables
    • Sending Notifications
  • Providers
    • DatabaseProvider
    • EmailProvider
    • SlackProvider
      • Slack BlockKit
    • Creating Custom Providers
  • Testing
    • Coming Soon
  • Reference
    • NotificationService
    • BaseNotification
    • SendsNotifications
    • INotifiable
    • BaseProvider
      • DatabaseProvider
        • DatabaseNotificationService
        • HasDatabaseNotifications
        • DatabaseNotificationCursor
        • DatabaseNotification
      • EmailProvider
      • SlackProvider
        • SlackMessage
          • EventMetadata
          • ActionsBlock
          • ContextBlock
          • DividerBlock
          • HeaderBlock
          • ImageBlock
          • SectionBlock
          • ButtonElement
          • ConfirmObject
          • ImageElement
          • TextObject
          • PlainTextOnlyTextObject
  • ForgeBox
  • GitHub
Powered by GitBook
On this page
  • INotifiable
  • via
  • routeNotificationFor
  1. Creating and Sending Notifications

Notifiables

A Notifiable is a something that can recieve a notification. Traditionally it is your User object, but it isn't limited to that. You may send notifications to a Team, a MailingList, a Site, or more.

INotifiable

A Notifiable needs to implement the INotifiable interface (implements keyword optional).

interface displayName="INotifiable" {

    /**
     * The id representing this notifiable.
     */
    public string function getNotifiableId();

    /**
     * The type name representing this notifiable.
     */
    public string function getNotifiableType();

}

An example implementation for a User component could be as follows:

component
    name="User"
    accessors="true"
    implements="megaphone.models.Interfaces.INotifiable"
{

    property name="id";
    
    /**
     * The id representing this notifiable.
     */
    public string function getNotifiableId() {
        return getId();
    }

    /**
     * The type name representing this notifiable.
     */
    public string function getNotifiableType() {
        return "user";
    }

}

via

Notifiable instances are passed to the via method on a Notification. This is to allow you to customize the channels used to each Notifiable. You may choose certain channels for a certain Notifiable type, like only sending SMS messages to User instances, not Team instances. You can also store Notifiable-specific configuration, like allowing a User to opt-in to certain channels like sms, email, or slack.

routeNotificationFor

Providers may look for a routeNotificationFor method suffixed with the Provider type name. For instance, the EmailProvider may look for a routeNotificationForEmail method on the Notifiable.

See the Provider-specific docs for more information.

PreviousDefining NotificationsNextSending Notifications

Last updated 1 year ago

See the for more information.

via docs on Notifications