-
Hi! I have a class DeleteUserNotifier < ApplicationNotifier
include FirebaseNotifier
validates :record, presence: true
notification_methods do
def url(*)
user_path(record)
end
def title
t('.title')
end
def body
t('.body', name: record.name)
end
end module FirebaseNotifier
extend ActiveSupport::Concern
included do
deliver_by :fcm do |config|
# ...
config.json = lambda { |device_token, notification|
{
message: {
token: device_token,
notification: { title: notification.title, body: notification.body }
}
}
}
end
end
end Previously, we were using Firebase as a custom method, and were able to access the So the question is; what do I need to do to be able to access Thanks in advance. :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
What does not work? |
Beta Was this translation helpful? Give feedback.
-
Yep, it was me missing something very obvious here 😅 This won't work as the passing symbol breaks: class TestNotifier < Noticed::Event
deliver_by :fcm do |config|
config.credentials = JSON.parse(Rails.application.credentials.firebase, symbolize_names: true)
config.device_tokens = -> { recipient.devices.where(token_type: :firebase).pluck(:token) }
config.queue = 'notifications'
config.invalid_token = ->(device_token) { recipient.devices.find_by(token: device_token).destroy }
config.json = :json_message
end
def json_message(device_token)
{
message: {
token: device_token,
notification: {
title:,
body:
},
webpush: {
fcm_options: {
link: url(web: true)
}
}
}
}
end
notification_methods do
def url(*)
'https://example.com/'
end
def title
'Test Title'
end
def body
'Test Body'
end
def name
'Test Name'
end
def channel_id
'Test Channel'
end
end
end Though it will work when it's used as the docs: class TestNotifier < Noticed::Event
deliver_by :fcm do |config|
config.credentials = JSON.parse(Rails.application.credentials.firebase, symbolize_names: true)
config.device_tokens = -> { recipient.devices.where(token_type: :firebase).pluck(:token) }
config.queue = 'notifications'
config.invalid_token = ->(device_token) { recipient.devices.find_by(token: device_token)&.destroy }
config.json = lambda { |device_token|
{
message: {
token: device_token,
notification: {
title:,
body:
},
webpush: {
fcm_options: {
link: url(web: true)
}
}
}
}
}
end
notification_methods do
def url(*)
'https://example.com/'
end
def title
'Test Title'
end
def body
'Test Body'
end
def name
'Test Name'
end
def channel_id
'Test Channel'
end
end
end TBH, I have no idea why I have used the symbol in the first place 😅 |
Beta Was this translation helpful? Give feedback.
Yep, it was me missing something very obvious here 😅
This won't work as the passing symbol breaks: