не могу получить уведомление от устройства к устройству после того, как я получил его впервые. Используете сервер node.js и npm? - PullRequest
0 голосов
/ 05 апреля 2020

Итак, я сделал node.js сервер для pu sh уведомления от устройства к устройству. Мне впервые удалось отправить уведомление sh, но после этого я не получаю уведомления. Хотя в логах уведомление отправляется каждый раз. Я не сделал никаких изменений в моем коде. вот мой код


const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.sendNotification = functions.firestore.document("Users/{user_id}/Notifications/{notification_id}").onWrite((change, context) => {

        const user_id = context.params.user_id;
        const notification_id = context.params.notification_id;

        console.log("User ID : " + user_id + " | Notification ID : " + notification_id)

return admin.firestore().collection("Users").doc(user_id).collection("Notifications").doc(notification_id).get().then(queryResult =>{




            const from_user_id = queryResult.data().from; 
            const from_message = queryResult.data().message;

            const from_data = admin.firestore().collection("Users").doc(from_user_id).get();
            const to_data = admin.firestore().collection("Users").doc(user_id).get();

                console.log("from_data : " + from_data + " | to_data : " + to_data)

            return Promise.all([from_data, to_data]).then(result => {
                const token_id = result[1].data().token_id;
                console.log("token id : "+token_id)



                const payload = {
                    notification: {
                        title : "Notification From : "+ from_user_id,
                        body : from_message,
                    }
                };

                return admin.messaging().sendToDevice(token_id, payload).then(result =>{
                    console.log("Notiication Send");
                });


});
});
});```

[![Notification that i recieved and logs[![\]\[1\]\[1\]][2]][2]


  [1]: https://i.stack.imgur.com/WPLh8.jpg
  [2]: https://i.stack.imgur.com/T1NGu.jpg
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...