0

私は認証トリガーを行っていますが、うまくいきます。誰かが自分のアカウントを削除した場合、そのユーザーは「このユーザーは自分のアカウント(電子メール)を削除しました」という通知に送信する必要があります。ここに私のコード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); 
     }) 
} 

答えて

1

は、あなたが入力エラー admin.messaging().sendToDevice()なくsendToDeveice

チェックがあります:https://firebase.google.com/docs/cloud-messaging/admin/send-messages

+0

私はそれらをチェックするが、イム私のsenarioにそれらを適用することができませんでしuがそれで私を助けることができます – HemalHerath

+0

メールをユーザーに送信したいと仮定しています。 https://github.com/firebase/functions-samples/blob/master/quickstarts/email-users/functions/indexをご覧ください。 js#L58 – Sichangi

+0

いいえ私はgivが必要ですあなたの実装に基づいて – HemalHerath

関連する問題