Skip to content

Instantly share code, notes, and snippets.

@t2
Created September 2, 2025 12:36
Show Gist options
  • Save t2/fe92cd1d5bd3ffdd268f8ea55ffb5706 to your computer and use it in GitHub Desktop.
Save t2/fe92cd1d5bd3ffdd268f8ea55ffb5706 to your computer and use it in GitHub Desktop.
Loops.so Noticed Integration
# 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
# 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
# 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