Skip to content

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

@dmatamoroscr

Description

@dmatamoroscr

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:

  • .perform_later(name, "#{notifier}::Notification", recipient: recipient, params: params)
    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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions