我已按照教程实施观察者通知。
exports.observeFollowing = functions.database.ref('/following/{uid}/{followingId}').onCreate((snapshot, context) => {
var uid = context.params.uid;
var followingId = context.params.followingId;
console.log('User: ' + uid + ' is following: ' + followingId);
return admin.database().ref('/users/' + followingId).once('value', snapshot => {
var userWeAreFollowing = snapshot.val();
return admin.database().ref('/users/' + uid).once('value', snapshot => {
var userDoingTheFollowing = snapshot.val();
var payload = {
notification: {
title: "You now have a new follower",
body: userDoingTheFollowing.username + "is now following you",
sound: 'default'
}
}
admin.messaging().sendToDevice(userWeAreFollowing.fcmToken, payload)
.then((response) => {
console.log('Successfully sent message:', response);
return response;
}).catch(function(error) => {
console.log('Error sending message:', error);
});
})
})
})
但是,当我尝试运行firebase deploy --only functions:observe之后,我收到以下错误:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我曾尝试从Stackoverflow搜索答案,但没有一个答案可行。