Search code examples
node.jsfirebase-cloud-messagingfirebase-admin

Firebase cloud messaging android priority property


I am attempting to set a notification priority to HIGH, as noted in the docs here and specific parameter defined here. However, when I set this property in my cloud function, I get the following error when attempting to deploy:

src/index.ts:107:35 - error TS2345: Argument of type '{ tokens: string[]; notification: { title: string; body: any; }; data: { title: any; subtitle: any; body: any; id: any; }; android: { notification: { icon: string; channel_id: string; tag: any; }; priority: string; }; }' is not assignable to parameter of type 'MulticastMessage'.
  The types of 'android.priority' are incompatible between these types.
    Type 'string' is not assignable to type '"normal" | "high" | undefined'.

107     admin.messaging().sendMulticast(message)
                                        ~~~~~~~

I understand this means I shouldn't be entering a string. But according to the docs, that's the expected type. Not only that, but I'm very confused on what type it's referring to in the quotations marks '"normal | "high" | undefined'. What is that type?

Here is the full message container being set:

const message = {
            tokens: tokens,
            notification: {
                title: snapshot.data().sender_username + " - " + snapshot.data().group_name,
                body: snapshot.data().content
            },
            data: {
                title: snapshot.data().group_name,
                subtitle: snapshot.data().sender_username,
                body: snapshot.data().content,
                id: message_topic
            },
            android: {
                notification: {
                    icon: 'add_circle_outline',
                    channel_id: 'exampleChannelId',
                    tag: message_topic

                },
                priority: "high" // <-- This is where the error is thrown
            }
        };

Solution

  • It seems that you need to set the priority in other locations, for it to be set correctly and no error be thrown. If you check this documentation here, it seems that it would need to be written in a different format.

    I did further investigation and I could find these two below posts on the Community, that might help you achieve your goal of setting the priority to high.

    This other article - Working easily with FCM push notifications in Android - might provide some additional ideas on how to achieve that.

    Let me know if the information helped you!