javascript - 通过在 android/java 中由 JavaScript 编写的函数在 FCM 中的同一应用程序中制作多种类型的通知
问题描述
我构建了一个应用程序,我需要在其中添加多种类型的通知,但我不能自己做,因为我对 JS 知之甚少
我尝试通过不同的主体、标题 ..etc 部署许多功能,但似乎无法在 Firebase Functions 中部署许多功能
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Noti/{receiver_user_id}/{notification_id}')
.onWrite((data, context) =>
{
const receiver_user_id = context.params.receiver_user_id;
const notification_id = context.params.notification_id;
console.log('We have a notification to send to :' , receiver_user_id);
if (!data.after.val())
{
console.log('A notification has been deleted :' , notification_id);
return null;
}
const DeviceToken = admin.database().ref(`/user/${receiver_user_id}/token`).once('value');
return DeviceToken.then(result =>
{
const token_id = result.val();
const payload =
{
notification:
{
title: "Open this notification now",
body: `I have a problem in my car `,
icon: "default" ,
sound: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload)
.then(response =>
{
console.log('This was a notification feature.');
});
});
});
这就是我要描述的问题
解决方案
是的,您可以部署各种功能,但您需要为每个功能设置不同的名称。函数名称在 after exports.
,因此您可以拥有:
exports.sendNotification
exports.newMessageNotification
exports.newFollowerNotification
...
他们每个人都会做你希望他们做的事情。
推荐阅读
- html - div 转到 CSS 中的下一行
- python - 为什么从请求切换到硒时代理不起作用?
- stata - Stata:结合多个 estpost 结果
- go - 在多个函数中使用init方法
- angular - 如何在 Electron 的 Angular 应用程序中创建和使用 V8 快照?
- payara - 是否可以从任何 YARA 模块获取当前系统时间?
- ios - 标签栏相互堆叠
- python - 在特定区域使用边缘权重进行反向传播
- php - 在使用 php 的 sql 查询中使用 case 函数时出错
- python - XOR MLP 与 GA,分析具有不同交叉/突变概率的图,可以得出什么结论?