【发布时间】:2019-01-09 19:41:40
【问题描述】:
您好,这是我也想用来将好友请求通知从一个应用发送到其他 Android 应用的代码。
但我得到函数返回undefined,预期的承诺或价值
函数控制台中的错误,我也没有得到令牌值..
我的代码在下面...
'use-strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.sendNotification = functions.firestore
.document("users/{user_id}/notifications/{notification_id}")
.onWrite((change,context)=>{
const user_id = context.params.user_id;
console.log("We have a notification to send to", user_id);
var ref = db.collection('device_token').doc(user_id);
var getDoc = cityRef.get().then(doc=>{
if (!doc.exists) {
return console.log('No such document!');
} else {
console.log('Document data:', doc.data());
const payload = {
notification: {
title: "Text.",
body: "You have a new Friend Request!",
icon: "default"
}
}
return admin.messaging().sendToDevice(tockenDoc, payload).then(response=>{
return console.log("Notification sent : success");
});
}
}).catch(err=>{
console.log('Error getting document', err);
});
});
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions