Cannot get device_tokens working for FCM delivery #388
-
I am using the following code for FCM delivery: deliver_by :fcm do |config|
config.credentials = "config/certs/fcm.json"
config.device_tokens = ->(recipient) { recipient.notification_tokens.where(platform: :fcm).pluck(:token) }
# config.device_tokens = ["foobar"]
config.json = ->(device_token) {
{
message: {
token: device_token,
notification: {
title: params[:invite].sender.handle,
body: message_body
}
}
}
}
end If I use the commented device_tokens line with an actual token string instead of the method version, the notification delivers via FCM to my device successfully.
I have looked at all of the bug reports, documentations, discussions, and haven't been able to find an answer. I assume their is just one minor thing I am doing wrong. Also, I should note, the method I am using to retrieve tokens from recipients is valid. Any help is appreciated, thank you. The full error:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is probably a mistake in our docs. When a lambda is passed here, it will not pass any arguments and evaluates the Proc in the context of the Noticed::Notification. So this should work instead: config.device_tokens = -> { recipient.notification_tokens.where(platform: :fcm).pluck(:token) } Any places in the docs you found this was wrong? Looks like the FCM docs need updating, but possibly the README as well. |
Beta Was this translation helpful? Give feedback.
This is probably a mistake in our docs. When a lambda is passed here, it will not pass any arguments and evaluates the Proc in the context of the Noticed::Notification. So this should work instead:
Any places in the docs you found this was wrong? Looks like the FCM docs need updating, but possibly the README as well.