Created
September 2, 2025 12:36
-
-
Save t2/fe92cd1d5bd3ffdd268f8ea55ffb5706 to your computer and use it in GitHub Desktop.
Loops.so Noticed Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/notifiers/general_notifier.rb | |
class GeneralNotifier < ApplicationNotifier | |
include LoopsNotifier | |
configure_loops | |
required_param :subject | |
required_param :message | |
notification_methods do | |
def loops(noticed_event) | |
variables = { message: params[:message], subject: params[:subject] } | |
{ | |
variables:, | |
transactional_id: '' | |
} | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/notifiers/delivery_methods/loops.rb | |
class DeliveryMethods::Loops < ApplicationDeliveryMethod | |
def deliver | |
loops_options = notification.loops(event) | |
data_variables = loops_options[:variables]&.merge(first_name: recipient.first_name) || { first_name: recipient.first_name } | |
LoopsSdk::Transactional.send( | |
data_variables:, | |
email: recipient.email, | |
transactional_id: loops_options[:transactional_id] | |
) | |
rescue LoopsSdk::APIError => e | |
Sentry.capture_exception(e) | |
Rails.logger.error("Loops API Error: #{e.json['message']} (Status: #{e.statusCode})") if Rails.env.development? | |
rescue StandardError => e | |
Sentry.capture_exception(e) | |
Rails.logger.error("Loops Error: #{e.inspect}") if Rails.env.development? | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/notifiers/concerns/loops_notifier.rb | |
module LoopsNotifier | |
extend ActiveSupport::Concern | |
class_methods do | |
def configure_loops(options = {}) | |
if options.key?(:wait) | |
deliver_by :loops, class: 'DeliveryMethods::Loops', wait: options[:wait], unless: -> { read? } | |
else | |
deliver_by :loops, class: 'DeliveryMethods::Loops', unless: -> { read? } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment