我试图通过Firebase云功能发出通知,但我的代码没有给出任何通知

问题描述:

我已经完成了身份验证触发器,它工作正常。如果有人删除了他们的账户,我需要发送通知“这个用户删除了他的账户(电子邮件)”。这里是我的代码我试图通过Firebase云功能发出通知,但我的代码没有给出任何通知

const functions = require('firebase-functions') 

//initialize the app 
const admin = require('firebase-admin') 
admin.initializeApp(functions.config().firebase) 

const ref = admin.database().ref() 

//create user account function 
exports.createUserAccount = functions.auth.user().onCreate(event => { 
    const uid = event.data.uid 
    const email = event.data.email 

    const newUserRef = ref.child(`/UserNotify/${uid}`) 
    return newUserRef.set({ 
     email: email 
    }) 
}) 

//delete user account function 
exports.cleanupUserData = functions.auth.user().onDelete(event => { 
    const uid = event.data.uid 
    const userRef = ref.child(`/UserNotify/${uid}`) 
    return userRef.update({isDeleted: true}) 
}) 

function sendNotification() { 

    console.log("Successfully sent"); 

    var payload = { 
     notification: { 
      title: "User get deleted", 
      body: "[email protected]" 
     } 
    }; 

    admin.messaging().sendToDeveice(payload) 
     .then(function (response) { 
      console.log("Successfully sent message:", response); 
     }) 
     .catch(function (error) { 
      console.log("Error sending message:", error); 
     }) 
} 

你可能有一个打字错误 admin.messaging().sendToDevice()而不是sendToDeveice

检查:https://firebase.google.com/docs/cloud-messaging/admin/send-messages

+0

我检查了,但即时通讯无法将它们应用到我的塞纳里奥u能帮助我与 – HemalHerath

+0

我假设你想发送电子邮件给用户, 看看这个例子: https://github.com/firebase/functions-samples/blob/master/quickstarts/email-users/functions/index。 js#L58 – Sichangi

+0

不,我需要giv e推送通知给其他用户使用我的应用程序“某人(电子邮件)删除他的帐户”,如 – HemalHerath