Javascript Firebase的云函数-部署时出错
我正在尝试部署一个函数,它侦听通知树,然后向用户发送推送通知 但是,如果继续出现这个错误(如下所示),我还有其他功能正在工作,似乎无法调试它 谢谢Javascript Firebase的云函数-部署时出错,javascript,firebase,firebase-realtime-database,firebase-cloud-messaging,google-cloud-functions,Javascript,Firebase,Firebase Realtime Database,Firebase Cloud Messaging,Google Cloud Functions,我正在尝试部署一个函数,它侦听通知树,然后向用户发送推送通知 但是,如果继续出现这个错误(如下所示),我还有其他功能正在工作,似乎无法调试它 谢谢 Error: Error occurred while parsing your function triggers. exports.sendFollowerNotification = functions.database.ref(‘/user_notifications/{userId}/{notificationId}’).onWrite(
Error: Error occurred while parsing your function triggers.
exports.sendFollowerNotification = functions.database.ref(‘/user_notifications/{userId}/{notificationId}’).onWrite(event => {
^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:16:9)
您缺少
functions
库的require
语句:var functions=require('firebase-functions')对不起,这是我的错,我忘了把它放在这个问题上,现在已经做了相应的编辑。谢谢。这里还有一些奇怪的反引号,似乎嵌套/配对不正确。例如,`/users/${userId}'
谢谢:)这很有效!
'use strict';
const functions = require('firebase-functions'),
admin = require('firebase-admin'),
logging = require('@google-cloud/logging')();
admin.initializeApp(functions.config().firebase);
exports.sendFollowerNotification = functions.database.ref(‘/user_notifications/{userId}/{notificationId}’).onWrite(event => {
const userId = event.params.userId;
const notificationId = event.params.notificationId;
const getDeviceTokensPromise = admin.database().ref(`/users/${userId}’).once('value');
const getNotificationPromise = admin.database().ref(‘/notifications/${notificationId}’).once('value');
return Promise.all([getDeviceTokensPromise, getNotificationPromise]).then(results => {
const userSnapshot = results[0];
const notification = results[1];
if (!userSnapshot.hasChildren()) {
return console.log('There is no user to send to.');
}
const payload = {
notification: {
title: ‘Covet Notification!’,
body: `${notification.description}`,
sound: 'default',
badge: '1'
}
};
const token = userSnapshot.pushToken
return admin.messaging().sendToDevice(token, payload)
});
});