Skip to content

Allow fcmOptions in payload keys #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Allow fcmOptions in payload keys #629

wants to merge 4 commits into from

Conversation

parndt
Copy link

@parndt parndt commented Aug 21, 2019

In #597 support was added for fcmOptions for specifying the analytics label for notifications.

Unfortunately, the list of valid payload keys wasn't extended to support it.

In #597 support was added for `fcmOptions` for specifying the analytics label for notifications.

Unfortunately, the allowable list of keys wasn't updated to support it.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@parndt
Copy link
Author

parndt commented Aug 22, 2019

@hiranya911 I tried to add all the right specs for this to ensure that this change is correct and avoids regressions, which pass locally, but I note that gulp build fails because of a missing index signature. Are you able to provide guidance here for me, please?

src/messaging/messaging.ts(775,33): error TS7017: Element implicitly has an 'any' type because type 'DataMessagePayload | FcmOptionsPayload | NotificationMessagePayload' has no index signature.

@parndt
Copy link
Author

parndt commented Aug 22, 2019

I opted for this implementation for the index signature:

/* Payload for fcmOptions messages */
export interface FcmOptionsPayload {
  analyticsLabel?: string;
  [key: string]: string;
}

you're welcome to edit the PR to adjust if this isn't suitable 😄 or just let me know what to change.

Thanks!

@hiranya911
Copy link
Contributor

I have a few concerns with this change.

  1. I don't think the legacy FCM API supports fcmOptions (see https://firebase.google.com/docs/cloud-messaging/http-server-ref).
  2. Even if it did, I don't know if we should be adding new features to the legacy API.

@chong-shao wdyt?

@parndt
Copy link
Author

parndt commented Aug 22, 2019

Thanks @hiranya911 for the review.

For some extra context which may help with deciding about this PR, here's how we're using this code inside a cloud function using messaging.sendToDevice:

const admin = require('firebase-admin')

admin.messaging().sendToDevice(
  pushToken,
  data: {
    custom_notification: JSON.stringify(
      Object.assign({ deepLink, show_in_foreground: true }, notification)
    ),
    deepLink,
  },
  fcmOptions: {
    analyticsLabel: 'test.analytics.label',
  },
  notification,
)

We saw this error:

{ Error: Messaging payload contains an invalid "fcmOptions" property. Valid properties are "data" and "notification".

I guess that is triggering usage of the legacy APIs when using MessagingPayload; is there another way to do this that uses the non-legacy API and allows us to use fcmOptions with analyticsLabel?
Does it involve this migration process ?

Thanks for your time! 😄

@hiranya911
Copy link
Contributor

You're using the legacy FCM APIs (sendToToken(), sendToDevice(), sendToDeviceGroup()). Those APIs don't support fcmOptions. You have to use the send() API for that. We have already added fcmOptions support there.

@hiranya911
Copy link
Contributor

@parndt please take a look at the Node.js examples on this page and update your code to use the new API: https://firebase.google.com/docs/cloud-messaging/send-message

The old API doesn't support fcmOptions.

@hiranya911 hiranya911 closed this Aug 22, 2019
@parndt parndt deleted the patch-1 branch August 22, 2019 23:27
@parndt
Copy link
Author

parndt commented Aug 22, 2019

Thanks a lot! 🙇‍♂️ that's exactly what I needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants