【问题标题】:I'm trying to give notification by Firebase cloud function, but my code doesn't give any notification我正在尝试通过 Firebase 云功能发出通知,但我的代码没有发出任何通知
【发布时间】:2017-07-27 04:21:43
【问题描述】:

我已经完成了身份验证触发器,它工作正常。如果有人删除他们的帐户,我需要像这样发送通知“此用户删除了他的帐户(电子邮件)”。这是我的代码

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: "sample@gmail.com"
        }
    };

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

【问题讨论】:

    标签: javascript node.js firebase firebase-cloud-messaging google-cloud-functions


    【解决方案1】:

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

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

    【讨论】:

    • 我检查了它们,但我无法将它们应用到我的 senario 中,你能帮我吗
    • 我假设你想给用户发送一封电子邮件,看看这个例子:github.com/firebase/functions-samples/blob/master/quickstarts/…
    • 不,我需要像这样向使用我的应用“某人(电子邮件)删除他的帐户”的其他用户发送推送通知
    • 根据您的实现,您将使用用户设备中的一组用户注册令牌,这些令牌可能存储在您的数据库中,并从 onDelete 事件中向他们发送已删除的电子邮件。
    猜你喜欢
    • 2019-02-23
    • 1970-01-01
    • 2020-07-31
    • 2021-04-04
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2018-08-05
    相关资源
    最近更新 更多