Tag: firebase cloud messaging

尝试通过Firebase云端function发送通知(Android)后出现错误

我是Firebase和nodejs的新手。 我正尝试使用Firebase云端函数从一台设备向另一台设备发送通知。 这是发送通知的node.js代码: var functions = require('firebase-functions'); var admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotification = functions.database.ref('/sendNotification/{notificationId}') .onWrite(event => { var regToken="fYRweeL8cic:APA91bH6Q_gyKKrLL…"; // Grab the current value of what was written to the Realtime Database. var eventSnapshot = event.data; var payload = { data: { title: eventSnapshot.child("title").val() } }; // Set the message as high priority and […]

如何发送通知给所有用户,除了android中的发件人使用节点js的firebase函数

我有一个firebase云function发送通知的主题。 问题是,它发送给所有用户,包括发件人,而我不希望它发送给发件人。 请不要提供订阅和取消订阅示例,因为我无法理解此解决scheme。 请帮忙? const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.pushNotification = functions.database.ref('/messages/{pushId}').onWrite( event => { console.log('Push notification event triggered'); var message1 = event.data.val(); if (!message1) { return; } var valueObject = message1.messageText; console.log('Push notification event triggered '+valueObject); const payload = { notification: { title:'Chat app', body: valueObject, }, }; const options […]

Firebase函数通知

我正尝试使用FCM服务发送简单的推送通知。 每当我的function被呼叫,我想收到一个通知,我希望我的手机振铃和振动。 我有两个问题: 当我收到通知时,我得到5个,而不是一个。 第二个问题是,如果我收到通知时手机的声音被激活,手机不会振动或振铃,但如果处于振动模式,则会在收到通知时振动。 任何想法如何解决这个问题? 谢谢! 'use strict' const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotification = functions.database.ref('/Alerts/{email_encoded}/{alert_id}').onWrite(event => { const email_encoded = event.params.email_encoded; const alert_id = event.params.alert_id; const deviceToken = admin.database().ref(`/Users/${email_encoded}/device_token`).once('value'); deviceToken.then(result => { const token_id = result.val(); const payload = { notification: { title: "Alert", body: "alert triggered", icon: "default", […]

firebasefunction来触发通知

我想创build一个firebase函数,当表中有新的条目时会触发一个通知。 我有包含所有设备令牌的单独的表。 无法弄清楚如何从表中获取每个设备令牌。 这里是我迄今为止写的一些firebase函数的代码片段,但没有运气。 'use strict'; const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotificationToAllMembers = functions.database.ref('/chatRoom/{messageNode}').onWrite(event => { const messageInfo = event.params.messageNode; // Get the list of device notification tokens. const getDeviceTokensPromise = admin.database().ref(`/deviceTokens`).once('value'); // Get newly added Message detail const getMovieMessageDetail = admin.database().ref(`/chatRoom/${messageInfo}`).once('value'); return Promise.all([getDeviceTokensPromise, getMovieMessageDetail]).then(results => { const deviceTokensList = results[0]; […]

从本地运行的云function调用“subscribeToTopic”

我不断收到权限错误… “尝试向FCM服务器进行身份validation时发生错误,请确保用于validation此SDK的凭据具有适当的权限,有关安装说明,请参阅https://firebase.google.com/docs/admin/setup 。 …当我在本地运行调用subscribeToTopic和unsubscribeToTopic的云function。 当我将我的函数部署到firebase时,这个问题不会发生。 我正在使用firebase-admin并在我的云端function中设置firebase … const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); authentication问题只发生在调用subscribeToTopic和unsubscribeToTopic 。 从云端函数写入数据库可以正常工作。 我可以通过调用admin.initializeApp通过admin.initializeApp控制台创build的生成的服务帐户json文件)来解决此问题。 任何想法,为什么发生这种情况?

Firebase云functionhttp触发响应函数循环

我写了一些代码发送一个通知给我的所有注册到一个事件的用户,我使用http触发器,将在事件启动时被调用,我不能发送通知到设备组,因为事件可能不同,即使开始时间是一样的。 我的firebase节点看起来像这样: registration |– userid1 | |– registration1 | | |– FirebaseToken | | |– EventName | |– registration2 | |– FirebaseToken | |– EventName |– userid2 这是我的脚本: exports.sendNotification = functions.https.onRequest((request, result) => { admin.database().ref('/registration').once('value').then(snapshot => { snapshot.forEach(childSnapshot => { let list = childSnapshot.val() for (let key in list) { let p = list[key]; let […]

FCM通知不显示应用程序终止时的iOS

我正在开发一个应用程序,该应用程序使用Firebase Cloud Messaging进行通知,我已经设置了我的应用程序以接收通知,并且还编写了一个基本的node.js服务器来自动处理发送通知。 一切工作正常,除非我似乎无法收到从我的服务器发送的通知,一旦应用程序被终止。 但是,从FCM控制台发送的通知可以很好地显示应用程序是否在后台运行。 我已经尝试添加一些字段到我的JSON数据在服务器消息(优先级,content_available等),但似乎没有任何工作。 这是我的json数据,包含通知: "notification" : { "title" : "New message", "body" : "You have a new message!", "sound" : "default", //"badge" : "1", //"content_available" : true, "priority" : "high" }, "to" : recipientID, 这里有我缺less的领域吗? 提前致谢!

将firebase函数转换为JavaScript的Typescript

我已经开始深入研究Firebase的云function,但是经过这么长时间,成为一名Android开发人员转而使用javascript已经非常艰难。 我已经使用firebase命令行工具(例如firebase login / init / deploy)configuration了一个新项目。 而且还需要npm和所有的依赖。 我正在使用Webstorm开发,并决定尝试按照YouTube上的video使用Typescript。 [ https://www.youtube.com/watch?v=GNR9El3XWYo&t=1106s] [1 ] 我已经设法得到我的Typescript编译,但是当转译为JavaScript时,它不能正确编译。 任何人都可以帮我解决这个问题吗? 下面的TS脚本 import * as functions from 'firebase-functions' import * as request from 'request-promise' export let addPlayerRequestNotification = functions.database .ref('notifications/{id}/notification') .onWrite(async event => { let notificaion = event.data.val(); let oauthToken = await functions.config().firebase.credential.getAccessToken(); await request ({ url: 'https://fcm.googleapis.com/fcm/send', method: 'POST', headers: […]

如何检查FCM消息状态?

我如何收到FCM的确认,收到了一条消息? 我有一个渐进的networking应用程序,检查用户是否有一个保存在数据库中的fcm令牌,如果他们这样做,并使用FCM,如果他们不这样做,并诉诸于SMS(通过twilio)。 问题在于即使closures浏览器,也会logging“”成功发送fcm消息“,因为消息排队等待浏览器重新打开。 我怎么能告诉用户实际上收到了一条消息,而不是等待在一个队列中? 如果Chrome已closures,则需要立即发送短信。 const functions = require('firebase-functions'); const admin = require('firebase-admin'); const serviceAccount = require('./service-account.json'); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: `https://${process.env.GCLOUD_PROJECT}.firebaseio.com` }); function sendFCM(uid, title, body) { const payload = { notification: { title: title, body: body, click_action: "https://www.google.com" } }; const payloadOptions = { timeToLive: 0 }; getUserDetails(uid).then((details) => { if (details.fcmToken !== […]

TypeError:无法读取Geolib.isDecimal处未定义的属性'toString'

我有一个使用Firebase云端function的推送通知系统,最近我注意到推送通知不再来了(他们在过去的几个月里一直在工作)。 当我进入日志我看到 TypeError: Cannot read property 'toString' of undefined at Geolib.isDecimal (/user_code/node_modules/geolib/dist/geolib.js:1326:26) at Geolib.useDecimal (/user_code/node_modules/geolib/dist/geolib.js:1241:22) at Geolib.coords (/user_code/node_modules/geolib/dist/geolib.js:179:85) at Geolib.getDistance (/user_code/node_modules/geolib/dist/geolib.js:247:26) at userValue (/user_code/index.js:104:34) at /user_code/index.js:94:4 at /user_code/node_modules/firebase-admin/lib/database/database.js:114:356 at Xb.h.ha (/user_code/node_modules/firebase-admin/lib/database/database.js:50:275) at Xb.h.ha (/user_code/node_modules/firebase-admin/lib/database/database.js:50:268) at Xb.h.ha (/user_code/node_modules/firebase-admin/lib/database/database.js:50:310) 我没有改变任何代码,并重新下载Geolib,但仍然不会改变,任何帮助将不胜感激。 我的代码: exports.postMade = functions.database.ref('/PostData/post/{pushId}').onWrite(event => { console.log('Someone made a post'); var valueObject = event.data.val(); console.log('the data in […]