Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

noticed

> 后端框架
Open source

Notifications for Ruby on Rails applications

2.7K stars0 likes1 views
WebsiteGitHub

About

Notifications for Ruby on Rails applications

Noticed

Notifications for your Ruby on Rails app.

Noticed is a gem that allows your application to send notifications of varying types, over various mediums, to various recipients. Be it a Slack notification to your own team when some internal event occurs or a notification to your user, sent as a text message, email, and real-time UI element in the browser, Noticed supports all of the above (at the same time)!

Noticed implements two top-level types of delivery methods:

  1. Individual Deliveries: Where each recipient gets their own notification
Show Example

Let’s use a car dealership as an example here. When someone purchases a car, a notification will be sent to the buyer with some contract details (“Congrats on your new 2024 XYZ Model...”), another to the car sales-person with different details (“You closed X deal; your commission is Y”), and another to the bank handling the loan with financial details (“New loan issued; amount $20,000...”). The event (the car being sold) necessitates multiple notifications being sent out to different recipients, but each contains its own unique information and should be separate from the others. These are individual deliveries.

  1. Bulk Deliveries: One notification for all recipients. This is useful for sending a notification to your Slack team, for example.
Show Example Let’s continue with the car-sale example here. Consider that your development team created the car-sales application that processed the deal above and sent out the notifications to the three parties. For the sake of team morale and feeling the ‘wins’, you may want to implement a notification that notifies your internal development team whenever a car sells through your platform. In this case, you’ll be notifying many people (your development team, maybe others at your company) but with the same content (“someone just bought a car through our platform!”). This is a bulk delivery. It’s generally a single notification that many people just need to be made aware of.

Bulk deliveries are typically used to push notifications to other platforms where users are managed (Slack, Discord, etc.) instead of your own.

Delivery methods we officially support:

  • ActionCable
  • Action Push Native
  • Apple Push Notification Service
  • Email
  • Firebase Cloud Messaging (iOS, Android, and web clients)
  • Microsoft Teams
  • Slack
  • Twilio Messaging - SMS, Whatsapp
  • Vonage SMS
  • Test

Bulk delivery methods we support:

  • Bluesky
  • Discord
  • Slack
  • Webhook

Screencast

Watch Screencast

Installation

Run the following command to add Noticed to your Gemfile:

ruby
bundle add "noticed"

Generate then run the migrations:

bash
rails noticed:install:migrations
rails db:migrate

Usage

Noticed operates with a few constructs: Notifiers, delivery methods, and Notification records.

To start, generate a Notifier:

bash
rails generate noticed:notifier NewCommentNotifier

Usage Contents

  • Notifier Objects
    • Delivery Method Configuration
    • Required Params
    • Helper Methods
    • URL Helpers
    • Translations
    • Tip: Capture User Preferences
    • Tip: Extracting Delivery Method Configurations
    • Shared Delivery Method Options
  • Sending Notifications
  • Custom Noticed Model Methods

Notifier Objects

Notifiers are essentially the controllers of the Noticed ecosystem and represent an Event. As such, we recommend naming them with the event they model in mind — be it a NewSaleNotifier, ChargeFailureNotifier, etc.

Notifiers must inherit from Noticed::Event. This provides all of their functionality.

A Notifier exists to declare the various delivery methods that should be used for that event and any notification helper methods necessary in those delivery mechanisms. In this example we’ll deliver by :action_cable to provide real-time UI updates to users’ browsers, :email if they’ve opted into email notifications, and a bulk notification to :discord to tell everyone on the Discord server there’s been a new comment.

…

For deeper specifics on setting up the :action_cable, :email, and :discord (bulk) delivery methods, refer to their docs: action_cable, email, and discord (bulk).

Delivery Method Configuration

Each delivery method can be configured with a block that yields a config object.

Procs/Lambdas will be evaluated when needed and symbols can be used to call a method.

When a lambda is passed, it will not pass any arguments and evaluates the Proc in the context of the Noticed::Notification

If you are using a symbol to call a method, we pass the notification object as an argument to the method. This allows you to access the notification object within the method. Your method must accept a single argument. If you don't need to use the object you can just use (*).

Show Example
…

More examples are in the docs for each delivery method.

Required Params

While explicit / required parameters are completely optional, Notifiers are able to opt in to required parameters via the required_params method:

ruby
class CarSaleNotifier < Noticed::Event
  deliver_by :email { |c| c.mailer = "BranchMailer" }

  # `record` is the Car record, `Branch` is the dealership
  required_params :branch

  # To validate the `:record` param, add a validation since it is an association on the Noticed::Event
  validates :record, presence: true
end

Which will validate upon any invocation that the specified parameters are present:

ruby
CarSaleNotifier.with(record: Car.last).deliver(Branch.last)
#=> Noticed::ValidationError("Param `branch` is required for CarSaleNotifier")

CarSaleNotifier.with(record: Car.last, branch: Branch.last).deliver(Branch.hq)
#=> OK

Helper Methods

Notifiers can implement various helper methods, within a notification_methods block, that make it easier to render the resulting notification directly. These helpers can be helpful depending on where and how you choose to render notifications. A common use is rendering a user’s notifications in your web UI as standard ERB. These notification helper methods make that rendering much simpler:

erb

On the other hand, if you’re using email delivery, ActionMailer has its own full stack for setting up objects and rendering. Your notification helper methods will always be available from the notification object, but using ActionMailer’s own paradigms may fit better for that particular delivery method. YMMV.

URL Helpers

Rails url helpers are included in Notifiers by default so you have full access to them in your notification helper methods, just like you would in your controllers and views.

But don't forget, you'll need to configure default_url_options in order for Rails to know what host and port to use when generating URLs.

ruby
Rails.application.routes.default_url_options[:host] = 'localhost:3000'

Translations

We've also included Rails’ translate and t helpers for you to use in your notification helper methods. This also provides an easy way of scoping translations. If the key starts with a period, it will automatically scope the key under notifiers, the underscored name of the notifier class, and notification. For example:

From the above Notifier...

ruby
class NewCommentNotifier < Noticed::Event
  # ...

  notification_methods do
    def message
      t(".message")
    end
  end

  # ...
end

Calling the message helper in an ERB view:

erb
<%= @user.notifications.last.message %>

Will look for the following translation path:

yaml
# ~/config/locales/en.yml

en:
  notifiers:
    new_comment_notifier:
      notification:
        message: "Someone posted a new comment!"

Or, if you have your Notifier within another module, such as Admin::NewCommentNotifier, the resulting lookup path will be en.notifiers.admin.new_comment_notifier.notification.message (modules become nesting steps).

Tip: Capture User Preferences

You can use the if: and unless: options on your delivery methods to check the user's preferences and skip processing if they have disabled that type of notification.

For example:

ruby
class CommentNotifier < Noticed::Event
  deliver_by :email do |config|
    config.mailer = 'CommentMailer'
    config.method = :new_comment
    config.if = ->{ recipient.email_notifications? }
  end
end

If you would like to skip the delivery job altogether, for example if you know that a user doesn't support the platform and you would like to save resources by not enqueuing the job, you can use before_enqueue.

For example:

ruby
class IosNotifier < Noticed::Event
  deliver_by :ios do |config|
    # ...
    config.before_enqueue = ->{ throw(:abort) unless recipient.registered_ios? }
  end
end

Tip: Extracting Delivery Method Configurations

If you want to reuse delivery method configurations across multiple Notifiers, you can extract them into a module and include them in your Notifiers.

…

Shared Delivery Method Options

Each of these options are available for every delivery method (individual or bulk). The value passed may be a lambda, a symbol that represents a callable method, a symbol value, or a string value.

  • config.if — Intended for a lambda or method; runs after the wait if configured; cancels the delivery method if returns falsey
  • config.unless — Intended for a lambda or method; runs after the wait if configured; cancels the delivery method if returns truthy

The following are evaluated in the context of the Notification so it can be customize to the recipient:

  • config.wait — (Should yield an ActiveSupport::Duration) Delays the job that runs this delivery method for the given duration of time
  • config.wait_until — (Should yield a specific time object) Delays the job that runs this delivery method until the specific time specified
  • config.queue — Sets the ActiveJob queue name to be used for the job that runs this delivery method.

When using a symbol, the matching method must be defined inside the notification_methods block:

ruby
# app/notifiers/message_notifier.rb
class MessageNotifier < Noticed::Event
  deliver_by :delivery_method do |config|
    config.queue = :queue
  end

  notification_methods do
    def queue
      "high_priority"
    end
  end
end

Sending Notifications

Following the NewCommentNotifier example above, here’s how we might invoke the Notifier to send notifications to every author in the thread about a new comment being added:

ruby
NewCommentNotifier.with(record: @comment, foo: "bar").deliver(@comment.thread.all_authors)

This instantiates a new NewCommentNotifier with params (similar to ActiveJob, any serializable params are permitted), then delivers notifications

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyemailnotificationsrailsruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架