noticed icon indicating copy to clipboard operation
noticed copied to clipboard

[BUG] Ephemeral notifiers send a notification object instead of the event to the delivery method

Open dmatamoroscr opened this issue 2 months ago • 0 comments

Bug Report

Describe the Bug: I'm attempting to use the ephemeral notifier with a bulk delivery method. However, by pairing these 2 together, I noticed the following:

  • evaluate_option in the delivery method returns nil (apparently the config in itself is an empty hash)
  • event is actually a notification object (which is inconsistent with the other notifiers)

To Reproduce:

  1. Create a bulk delivery method (I created a slack one to use some custom logic we have, but I guess the regular slack one in the gem should work).
class DeliveryMethods::SlackMessenger < Noticed::BulkDeliveryMethod
  required_options :channel_ids, :message_obj

  def deliver
    channel_ids = evaluate_option(:channel_ids)
    message_obj = evaluate_option(:message_obj)
    user_channel_ids = Array(event.try(:user_recipients)).map(&:slack_channel_id) # user_recipients is a has_many relation I added to the base ApplicationNotifier class as shortcut to get the users.

    (channel_ids + user_channel_ids).flatten.compact.uniq.each do |channel_id|
      post_message(channel_id, message_obj)
    end
    ...
  end
  1. Create an ephemeral notifier
class MyEphemeralNotifier < Noticed::Ephemeral
    bulk_deliver_by :slack_messenger, class: "DeliveryMethods::SlackMessenger" do |config|
      config.message_obj = -> { slack_message_obj }
      config.channel_ids = -> { slack_channel_ids }
    end

    def slack_channel_ids
      []
    end

    def slack_message_obj
       {...}
    end
end

Expected Behavior: Slack notification is delivered and no notification records are stored due to the ephemeral notifier being used.

Actual Behavior:

  • Undefined method user_recipients called on MyEphemeralNotifier::Notification
  • message_obj and channel_ids evaluated options return nil

Environment:

  • Noticed gem version: 2.8.0
  • Ruby version: 3.3.9
  • Rails version: 8.1.1
  • Operating System: WSL2

Possible Fix:

  • https://github.com/excid3/noticed/blob/05c1acac2544c0dc018def69b7244ec8d74fff5c/app/models/noticed/deliverable/deliver_by.rb#L27 This should probably use the notifier/event class instead of the Notification
  • Regarding the empty config, I'm not sure how that gets pulled.
  • Additional examples on how to use the ephemeral class would be helpful

Checklist:

  • [x] I have searched for similar issues and couldn't find any
  • [x] I have checked the documentation for relevant information
  • [x] I have included all the required information

dmatamoroscr avatar Nov 19 '25 23:11 dmatamoroscr