firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.63k stars 371 forks source link

Error: Unknown name "body_lock_key", "title_lock_key" #457

Closed zolkiBy closed 5 years ago

zolkiBy commented 5 years ago

I want to send notification to individual android device. My function:

exports.myFunction = functions.firestore
.document('path/{dataId}')
.onUpdate((change, context) => {
    const data = change.after.data();
    console.log('Update data', context.params.dataId, data);

    const dataId = context.params.dataId;
    const registrationToken = token;
    const instruction = data.instruction;       

    if(instruction !== null){
        const message = {
        data: {
                data_id: dataId
            },
            android: {
                ttl: 0,
                priority: 'high',
                notification: {
                    clickAction: '.clickAction',
                    bodyLockKey: 'notification_body_loc_key'
                }
            },
            token: registrationToken
        };

        console.log('message - ', message);
        admin.messaging().send(message);                
    }

    return null;        
});

But when action is triggering, I receive error in console:

Error: Invalid JSON payload received. Unknown name "body_lock_key" at 'message.android.notification': Cannot find field.
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16)
at Function.FirebaseMessagingError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:271:16)
at FirebaseMessagingRequestHandler.handleHttpError (/user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:125:50)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:113:23
at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Also same error with titleLockKey:


Invalid JSON payload received. Unknown name "title_lock_key" at 'message.android.notification': Cannot find field.
    at FirebaseMessagingError.Error (native)
    at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
    at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
    at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16)
    at Function.FirebaseMessagingError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:271:16)
    at FirebaseMessagingRequestHandler.handleHttpError (/user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:125:50)
    at /user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:113:23
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
hiranya911 commented 5 years ago

@chong-shao this error is coming from the backend server. body_loc_key and title_loc_key are listed as supported here: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#AndroidNotification

chong-shao commented 5 years ago

Have you tried "titleLocKey" and "BodyLocKey" instead of "titleLockKey"?

hiranya911 commented 5 years ago

@zolkiBy as @chong-shao pointed out you have typos in your code. You need to correct them.