如何在JS中从Firebase数据库引用节点?

时间:2018-06-22 18:28:43

标签: javascript android firebase-realtime-database google-cloud-functions

在引用我的Firebase数据库中的特定节点时,我需要帮助。 “群聊节点的系统开发节点中的消息节点”。任何人?到目前为止,这是您的代码。

我的JS文件

exports.sendNotification7 = functions.database.ref('/GroupChat/{SDevtChat}/{SDevtChatId}/message')
    .onWrite(( change,context) =>{

    // Grab the current value of what was written to the Realtime Database.
    var eventSnapshot = change.after.val();
    var str = "New message from System Development Group Chat: " + eventSnapshot;
    console.log(eventSnapshot);

    var topic = "Management.Information.System";
    var payload = {
        data: {
            name: str,
        }
    };

    // Send a message to devices subscribed to the provided topic.
    return admin.messaging().sendToTopic(topic, payload)
        .then(function (response) {
            // See the MessagingTopicResponse reference documentation for the
            // contents of response.
            console.log("Successfully sent message:", response);
            return;
        })
        .catch(function (error) {
            console.log("Error sending message:", error);
        });
    });

My Database Snapshot

0 个答案:

没有答案