Hey,
ich möchte das eine Notification von den Firebase Function Server gesendte wird. Dazu hab ich erstmal folgenden Code:
Allerdings kommt am Handy keine Benachrichtigung an. Könnte mir jemand bei dieser Sache helfen?
ich möchte das eine Notification von den Firebase Function Server gesendte wird. Dazu hab ich erstmal folgenden Code:
Java:
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/notifications/{user_id}/{notification_id}').onWrite((change, context) => {
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
console.log('We have a notification from : ', context.params.user_id);
const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');
return deviceToken.then(result =>{
const token_id = result.val();
console.log('Token ID: ', token_id);
const payload = {
notification: {
title: "Neue Nachricht",
body: "Du hast eine neue Nachricht erhlaten",
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(response =>{
return console.log('This was the notification');
});
});
});