无法获取Firebase Cloud Functions以在我的集合的onWrite上触发Firestore。正在尝试为聊天应用设置设备到设备推送通知。功能已部署且按需付费计划,但是文档中的更改、更新或“聊天”集合中的创建不会触发。Firebase云消息应该发送推送并写入日志。这两种情况都没有发生。Push正在与其他资源协同工作。
感谢你的帮助,希望设备到设备的推送通知更容易,计划是观看聊天文档并在更新或创建新对话时触发推送通知。对其他想法持开放态度。谢谢
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.firestore
.document('chats/{chatID}')
.onWrite((data, context) => {
// Get an object representing the document
console.log('chat triggered');
// perform desired operations ...
// See documentation on defining a message payload.
var message = {
notification: {
title: 'Hello World!',
body: 'Hello World!'
},
topic: context.params.chatID
};
// Send a message to devices subscribed to the provided topic.
return admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
return true
})
.catch((error) => {
console.log('Error sending message:', error);
});
});
更新:我使用的是“firebase函数”:"^1.0.1“
更新:更新了代码,以反映我们当前部署的内容,但仍然不起作用。
https://stackoverflow.com/questions/50206137
复制相似问题