firebase - 在 Firebase 中使用函数向(分析)受众发送推送通知
问题描述
我已使用 Firebase 函数触发的 Firebase 云消息传递 (FCM) 成功发送通知:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const fs = require('fs');
admin.initializeApp();
exports.testNotif = functions.https.onRequest((request, response) => {
const mySecretNumber = getRandomInt(147)
var payload = {
notification: {
title: `You got a new Message`,
body: `My highest break ${mySecretNumber}`,
badge: mySecretNumber.toString(),
sound: `notif1.aiff`,
}
};
const ackString = `All done ${mySecretNumber}`;
console.log(ackString)
response.send(ackString);
//send to all topic
admin.messaging().sendToTopic(`all`, payload)
});
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
如您所见,我将通知发送到一个名为“全部”的主题。
在 Firebase 控制台中,您可以向可以创建的受众发送通知。就我而言,我根据分析模块中的用户属性创建了不同的受众。
是否也可以通过 Firebase Functions 向受众发送通知?
解决方案
没有分析 API 可以检索属于特定分析受众的用户。也没有 FCM API 可以向此类受众发送通知。
如果您想向受众发送通知,则必须创建自己的方式来定义这些受众。最直接的方法是将 Google Analytics for Firebase 连接到 BigQuery,然后根据您在那里收到的分析事件定义受众。
推荐阅读
- javascript - 在Javascript中生成一个随机整数,不包括数字数组
- ms-word - MS Word 加载项内容控件,带有类似按钮的对话框触发器
- less - 使用 less 时出现一些奇怪的错误
- c# - 带有阿拉伯文文本的 Xaml 字形
- php - 根据用户表[laravel]中的列使用orderBy()订购产品表
- parsing - 将大型文档/文本/HTML 分解成段的良好 ML 模型/技术是什么?
- arrays - 通过在 Perl 中通过数组的哈希映射第一个索引来获取第二个索引的值
- sql - 相同的时间戳 orderBy
- android - 无法更新设备上的文件:HttpException:在收到完整标头之前连接已关闭
- html - 如何修复有时有效但有时跳转到错误位置的锚链接?