Cloud Functions for Firebase FCM reference error
error
ReferenceError: functions is not defined at Object. (C:UsersCROWDE~1AppDataLocalTempfbfn_9612Si4u8URDRCrrindex.js:5:21) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at C:UserscrowderiaAppDataRoamingnpmnode_modulesfirebase-toolslibtriggerParser.js:18:11 at Object. (C:UserscrowderiaAppDataRoamingnpmnode_modulesfirebase-toolslibtriggerParser.js:32:3)
index.js file like below
'use strict'
const funnctions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite(event => {
const user_id = event.params.user_id;
const notification_id = event.params.notification_id;
cosole.log('User id is : ', user_id);
if (!event.data.val()) {
return console.log('A Notification has been deleted from the database : ', notification_id);
}
const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');
return deviceToken.then(result => {
const token_id = result.val();
const payload = {
notification: {
title: "Friend Request",
body: "You've received a new Friend Request",
icon: "default",
}
};
return admin.messaging().sendToDevice(token_id, payload).then(response => {
console.log('this is the notification feature');
});
});
});
You have a typo right in the first line
const funnctions = require('firebase-functions');
functions, not funnctions :) so that this line
functions.database.ref('/Notifications/{user_id...
would work
链接地址: http://www.djcxy.com/p/33040.html上一篇: 在执行快速会话时发生错误