【发布时间】:2019-07-04 14:34:17
【问题描述】:
我正在尝试向我的应用程序添加通知功能,以便一旦用户发布帖子,任何订阅他们的人都会收到通知。目前我正在尝试编写一个云函数来实现这一点。
但是,编写一个小测试未能部署到我的项目中。
注意:如果有人有关于如何为 Flutter 完成类似操作的链接,我们将不胜感激。
我查看了我能找到的几个示例,趋势是 js 代码有问题,但我看不到任何示例。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification =
functions.firestore.document('Orders/{resturantId}/Orders')
.onWrite((change, context) =>{
const notificationContent = {
notification:{
title: "/*App name */",
body: "You have a new Comment!",
icon: "default",
click_action: "/*Package */_TARGET_NOTIFICATION"
}
};
return admin.messaging().sendToTopic("-LV_05ip0wf1dFEg45wx", notificationContent)
.then(result => {
console.log("Notification sent!");
return;
});
});
【问题讨论】:
-
请编辑问题以显示
firebase deploy的整个输出,确认该功能已部署。 -
看起来您的 .js 文件放错了位置,或者您在路径的错误部分运行了 firebase cli - 请仔细检查这些内容...
-
您能详细说明一下吗?检查路径它表明我有一个 index.js 里面
标签: javascript firebase flutter google-cloud-firestore google-cloud-functions