我正在尝试部署一个侦听通知树的函数,然后向用户发送推送通知。
然而,继续得到这个错误(见下文),我有其他功能正在工作,似乎无法调试。
感谢。
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)
这是我的代码功能代码:
'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)
});
});